社区
C#
帖子详情
WPF(使用C#)中关于自定义窗体的问题
PeterZeng43
2016-10-05 01:45:24
我用WPF写了一个程序,为了增强UI的美感,我想把主窗体的标题栏与按钮弄成纯黑色,像这样:
请问应该如何重写模板代码呢?希望各位大神给出详细的指导,感激不尽。
...全文
317
6
打赏
收藏
WPF(使用C#)中关于自定义窗体的问题
我用WPF写了一个程序,为了增强UI的美感,我想把主窗体的标题栏与按钮弄成纯黑色,像这样: 请问应该如何重写模板代码呢?希望各位大神给出详细的指导,感激不尽。
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
glgt_flyy
2016-10-08
打赏
举报
回复
窗体风格设置为NONE,然后自己在界面再把标题栏和按钮画出来,实现按钮功能就可以了,风格随便改
郑州高新区WPF小王子
2016-10-07
打赏
举报
回复
自己写一个用户控件,增加几个依赖项属性,比如背景色,在引用用户控件时 对属性赋值。
xinbada1985
2016-10-05
打赏
举报
回复
可以调你想要的各种颜色
xinbada1985
2016-10-05
打赏
举报
回复
<ControlTemplate x:Key="WindowTemplateKey" TargetType="{x:Type Window}"> <DockPanel LastChildFill="True"> <!--外边框--> <Border Width="Auto" Height="30" DockPanel.Dock="Top" Background="{StaticResource SubWindowBackGroundColor}" BorderBrush="{StaticResource SubWindowBackGroundColor}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="4,4,0,0" x:Name="borderTitle"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="25" ></ColumnDefinition> <ColumnDefinition Width="*" ></ColumnDefinition> <ColumnDefinition Width="25" ></ColumnDefinition> </Grid.ColumnDefinitions> <Image Margin="5,8,0,0" Source="{TemplateBinding Icon}" HorizontalAlignment="Left" VerticalAlignment="Top"/> <Label Padding="0" Foreground="White" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Margin="0,8,0,0" Grid.Column="1" Content="{TemplateBinding Title}"></Label> <!--关闭按钮--> <Button Grid.Column="2" x:Name="btnClose" Style="{StaticResource ButtonTool}" Margin="0,8,5,0" HorizontalAlignment="Right" VerticalAlignment="Top"> <materialDesign:PackIcon Foreground="White" Kind="WindowClose" HorizontalAlignment="Center" VerticalAlignment="Center"/> </Button> </Grid> </Border> <Border Background="{StaticResource SubWindowBackGroundColor}" BorderBrush="{StaticResource SubWindowBackGroundColor}" BorderThickness="{TemplateBinding BorderThickness}" Width="Auto" Height="Auto" DockPanel.Dock="Top" CornerRadius="0,0,4,4"> <AdornerDecorator> <ContentPresenter /> </AdornerDecorator> </Border> <ResizeGrip Visibility="Collapsed" IsTabStop="false" HorizontalAlignment="Right" x:Name="WindowResizeGrip" VerticalAlignment="Bottom" /> </DockPanel> <ControlTemplate.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="ResizeMode" Value="CanResizeWithGrip" /> <Condition Property="WindowState" Value="Normal" /> </MultiTrigger.Conditions> <Setter Property="Visibility" TargetName="WindowResizeGrip" Value="Visible" /> </MultiTrigger> </ControlTemplate.Triggers> </ControlTemplate> <ControlTemplate x:Key="BaseWindowControlTemplate" TargetType="{x:Type Window}"> <DockPanel LastChildFill="True"> <!--外边框--> <Border Width="Auto" Height="30" DockPanel.Dock="Top" Background="{StaticResource SubWindowBackGroundColor}" BorderBrush="{StaticResource SubWindowBackGroundColor}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="4,4,0,0" x:Name="borderTitle"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="25" ></ColumnDefinition> <ColumnDefinition Width="*" ></ColumnDefinition> <ColumnDefinition Width="25" ></ColumnDefinition> </Grid.ColumnDefinitions> <Image Margin="5,8,0,0" Source="{TemplateBinding Icon}" HorizontalAlignment="Left" VerticalAlignment="Top"/> <Label Padding="0" Foreground="White" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Margin="0,8,0,0" Grid.Column="1" Content="{TemplateBinding Title}"></Label> <!--关闭按钮--> <Button Grid.Column="2" x:Name="btnClose" Style="{StaticResource ButtonTool}" Margin="0,8,5,0" HorizontalAlignment="Right" VerticalAlignment="Top"> <materialDesign:PackIcon Foreground="White" Kind="WindowClose" HorizontalAlignment="Center" VerticalAlignment="Center"/> </Button> </Grid> </Border> <Border Background="{StaticResource SubWindowBackGroundColor}" BorderBrush="{StaticResource SubWindowBackGroundColor}" BorderThickness="{TemplateBinding BorderThickness}" Width="Auto" Height="Auto" DockPanel.Dock="Top" CornerRadius="0,0,4,4"> <AdornerDecorator> <ContentPresenter /> </AdornerDecorator> </Border> </DockPanel> </ControlTemplate> <Style x:Key="BaseWindowStyle" TargetType="{x:Type Window}"> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" /> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" /> <Setter Property="Template" Value="{StaticResource BaseWindowControlTemplate}"/> <Setter Property="AllowsTransparency" Value="True" /> <Setter Property="WindowStyle" Value="None" /> <Setter Property="BorderBrush" Value="{StaticResource SubWindowBackGroundColor}" /> <Setter Property="BorderThickness" Value="4,0,4,4" /> <Setter Property="Opacity" Value="1" /> <Style.Triggers> <Trigger Property="ResizeMode" Value="CanResizeWithGrip"> <Setter Property="Template" Value="{StaticResource WindowTemplateKey}" /> </Trigger> </Style.Triggers> </Style> 这是window的样式SubWindowBackGroundColor这个是window的背景色自己可以研究一下!
D56233577
2016-10-05
打赏
举报
回复
希望界面美观的话,应该让所有控件的风格保持一致,不能既拥有Win10的暗色标题栏,又拥有XP的亮色圆角按钮,这种界面能看? 对界面做大的改造又要保持风格一致,代码量是非常大的,你没有这个能力,建议你直接用第三方类库就好了。
D56233577
2016-10-05
打赏
举报
回复
WPF默认模板使用了和系统挂钩的组建,也就是说在不同系统下外观是不一样的,如果你的美感不是建立在某个具体的操作系统之上,那么使用Mahapps这类开源类库是最佳的方案,可以使用不同的主题色。当然,如果你有精力,你可以重写所有模板。
WPF
之
自定义
窗体
的封装
总之,封装
自定义
窗体
是
WPF
开发
中
的重要技巧,它结合了XAML的声明式设计和
C#
的编程能力,使得开发者能够创造出独特且符合应用需求的用户界面。通过熟练掌握这一技能,可以在
WPF
项目
中
游刃有余,为用户提供更加直观、...
C#
wpf
在style
中
自定义
标题栏及无边框窗口
本资源实现了一种
wpf
在style
中
自定义
标题栏无边框窗口的方法。style内部的实现其实没那么简单,尤其是实现按钮逻辑以及拖动逻辑,需要在style
中
关联cs代码,这就要求我们熟悉绑定技巧、附加属性还有ContentPresenter...
C#
多线程
自定义
窗体
读取VF数据库
2. **
自定义
窗体
**:在Windows Forms或
WPF
应用
中
,开发者可以通过继承`Form`类或`Window`类来创建
自定义
的用户界面。这可以包括添加控件、设置布局以及实现特定的业务逻辑。在本项目
中
,可能包含了一个能够显示进度...
C#
wpf
自定义
替换系统的MessageBox
《
C#
wpf
实现
自定义
界面操作分离的MessageBox》
中
我们得到了一个功能完整的MessageBox的功能逻辑,将功能逻辑进行拓展,程序启动的时候,hook系统的MessageBox,变成调用自己的MessageBox。那我们只需要定义一个...
wpf
自定义
窗体
标题提到的"
wpf
自定义
窗体
"是一个关于如何在
WPF
中
设计并实现个性化窗口的实践案例。描述
中
提到了
窗体
的阴影部分可能过于臃肿,并暗示可以通过
使用
放射性渐变填充来优化这个
问题
,这涉及到图形渲染和UI设计的优化技巧...
C#
111,097
社区成员
642,554
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章