社区
C#
帖子详情
WPF(使用C#)中关于自定义窗体的问题
PeterZeng43
2016-10-05 01:45:24
我用WPF写了一个程序,为了增强UI的美感,我想把主窗体的标题栏与按钮弄成纯黑色,像这样:
请问应该如何重写模板代码呢?希望各位大神给出详细的指导,感激不尽。
...全文
320
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
自定义
窗体
的实现,https://blog.csdn.net/me_badman/article/details/83345502
C#
wpf
在style
中
自定义
标题栏及无边框窗口
本资源实现了一种
wpf
在style
中
自定义
标题栏无边框窗口的方法。style内部的实现其实没那么简单,尤其是实现按钮逻辑以及拖动逻辑,需要在style
中
关联cs代码,这就要求我们熟悉绑定技巧、附加属性还有ContentPresenter 。但是好处也是明显的,及时具有了通用性,无论是哪个
窗体
都可以
使用
。本资源是完整的源码,vs2019的项目可直接运行。原文链接:https://blog.csdn.net/u013113678/article/details/121058798
C#
多线程
自定义
窗体
读取VF数据库
多线程实现内部逻辑,运行时
窗体
可响应其它消息。 读取并处理理VF数据,输出Excel用的csv格式文件。
C#
wpf
自定义
替换系统的MessageBox
《
C#
wpf
实现
自定义
界面操作分离的MessageBox》
中
我们得到了一个功能完整的MessageBox的功能逻辑,将功能逻辑进行拓展,程序启动的时候,hook系统的MessageBox,变成调用自己的MessageBox。那我们只需要定义一个自己的MessageBox界面,绑定必要的属性,即可直接替换系统的MessageBox,或者说可以修改系统MessageBox的样式。原文链接:https://blog.csdn.net/u013113678/article/details/120934560。本资源是完整的源码,但Hook部分核心代码不可见,具体实现封装在C++的dll
中
,且dll只提供MessageBoxW和MessageBoxA的Hook和Unhook,请根据需要下载。
wpf
自定义
窗体
这个是最终版的
wpf
自定义
窗体
,阴影部分有点臃肿了,本可以用放射性渐变填充的,以后用着不舒服可以改
C#
111,098
社区成员
642,554
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章