社区
C#
帖子详情
WPF(使用C#)中关于自定义窗体的问题
PeterZeng43
2016-10-05 01:45:24
我用WPF写了一个程序,为了增强UI的美感,我想把主窗体的标题栏与按钮弄成纯黑色,像这样:
请问应该如何重写模板代码呢?希望各位大神给出详细的指导,感激不尽。
...全文
304
6
打赏
收藏
WPF(使用C#)中关于自定义窗体的问题
我用WPF写了一个程序,为了增强UI的美感,我想把主窗体的标题栏与按钮弄成纯黑色,像这样: 请问应该如何重写模板代码呢?希望各位大神给出详细的指导,感激不尽。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
glgt_flyy
2016-10-08
打赏
举报
回复
窗体风格设置为NONE,然后自己在界面再把标题栏和按钮画出来,实现按钮功能就可以了,风格随便改
exception92
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这类开源类库是最佳的方案,可以使用不同的主题色。当然,如果你有精力,你可以重写所有模板。
C#
wpf
在style
中
自定义
标题栏及无边框窗口
本资源实现了一种
wpf
在style
中
自定义
标题栏无边框窗口的方法。style内部的实现其实没那么简单,尤其是实现按钮逻辑以及拖动逻辑,需要在style
中
关联cs代码,这就要求我们熟悉绑定技巧、附加属性还有ContentPresenter...
WPF
之
自定义
窗体
<p>
WPF
自定义
窗体
源码(完全将
WPF
中
Window拆开,重新定义); 项目分两部分:Florid-
自定义
窗体
类库;FloridSamples-引用Florid类库实现
自定义
窗体
;实现的功能: 重定义
窗体
样式;最小化、最大化、关闭按钮;
窗体
移动、...
C#
自定义
窗体
的最大化、最小化和关闭按钮
自定义
窗体
的最大化、最小化和关闭按钮,
C#
移动无标题栏
窗体
的三种代码:
C#
移动无标题栏
窗体
的三种代码:第一种采用,需注意
窗体
上的控件是否把
窗体
覆盖了。。。MouseDown、MouseMove、MouseUp事件应该是鼠标所...
WPF
窗体
拖拽效果,
窗体
随鼠标移动
实现类似拖拽效果: 1、按键按下新建
窗体
2、新建
窗体
随鼠标移动 3、松开鼠标取消移动
wpf
控件 完美九宫格
自定义
窗体
原版本:http://download.csdn.net/download/beilinu/6645569 此为修改的版本,解决了
wpf
中
九宫格显示存在白线的
问题
C#
110,533
社区成员
642,574
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章