社区
C#
帖子详情
WPF(使用C#)中关于自定义窗体的问题
PeterZeng43
2016-10-05 01:45:24
我用WPF写了一个程序,为了增强UI的美感,我想把主窗体的标题栏与按钮弄成纯黑色,像这样:
请问应该如何重写模板代码呢?希望各位大神给出详细的指导,感激不尽。
...全文
377
6
打赏
收藏
WPF(使用C#)中关于自定义窗体的问题
我用WPF写了一个程序,为了增强UI的美感,我想把主窗体的标题栏与按钮弄成纯黑色,像这样: 请问应该如何重写模板代码呢?希望各位大神给出详细的指导,感激不尽。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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这类开源类库是最佳的方案,可以使用不同的主题色。当然,如果你有精力,你可以重写所有模板。
C Winform
使用
WPF
控件
C#
Winform
使用
WPF
控件 去发现同类优质开源项目:https://gitcode.com/ 此资源文件为
C#
Winform
窗体
应用程序的示例代码,主要展示了如何在Winform应用程序
中
加载并
使用
WPF
(Windows Presentation Foundation)
自定义
控件。通过此示例,开发者可以了解到Winform与
WPF
两种技术的融合应用,进一步优化和提升应用程序的用户界面和用...
各种
窗体
——CAD
【代码】各种
窗体
——gileCAD。
C#
完美将第三方
窗体
嵌入Panel容器(
WPF
、Winform)
完美将第三方应用嵌入自己的
窗体
,适用于Winform和
WPF
,把第三方的窗口嵌入到
WPF
的界面的一个Panel当
中
,实现起来还是很简单的,只要知道这个
窗体
的名称即可。以下为代码,SetWindow类为
窗体
设置类,对
窗体
的设置都在其
中
完成。.....................
WPF
自定义
窗体
封装技术详解与实践
WPF
(Windows Presentation Foundation)是微软推出的一种用于构建Windows客户端应用程序的用户界面框架。它允许开发者通过XAML(可扩展应用程序标记语言)来设计和实现用户界面,与传统的Windows
窗体
相比,
WPF
提供了更丰富的视觉效果和更灵活的用户界面设计。在
WPF
中
,类的定义是面向对象编程的基础。每一个
WPF
控件,从Button到Window,都是继承自一个共同的基类。比如,
自定义
窗体
类通常继承自Window类。
WPF
实现类似MDI子
窗体
的功能
在我的上一篇博客
中
http://blog.csdn.net/soft2buy/article/details/5479946,提到了用UserControl做为
WPF
的“MDI子
窗体
”。今天偶然发现 XCeed 开发的Extended
WPF
Toolkit里面有个ChildWindow
窗体
可以做为MainWindow的子
窗体
。ChildWindow也是从UserControl继乘的。 先看
C#
111,129
社区成员
642,533
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章