社区
C#
帖子详情
WPF(使用C#)中关于自定义窗体的问题
PeterZeng43
2016-10-05 01:45:24
我用WPF写了一个程序,为了增强UI的美感,我想把主窗体的标题栏与按钮弄成纯黑色,像这样:
请问应该如何重写模板代码呢?希望各位大神给出详细的指导,感激不尽。
...全文
370
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
窗体
应用示例代码,展示了在Winform应用
中
加载并
使用
WPF
自定义
控件,体现了Winform与
WPF
的融合应用,有助于优化应用界面与体验。文件含核心代码和集成步骤,
使用
时需注意环境安装、包安装及兼容性
问题
。
各种
窗体
——CAD
本文介绍在AutoCAD环境下
使用
C#
进行
自定义
窗体
(如Windows Forms和
WPF
)开发的技术要点,涵盖
窗体
集成、事件绑定、与CAD命令交互、UI线程安全调用及AcadApplication对象协同等核心实践。重点解决模态/非模态
窗体
加载、数据回传及界面响应优化
问题
,适用于CAD二次开发者。
C#
完美将第三方
窗体
嵌入Panel容器(
WPF
、Winform)
本文介绍了如何
使用
C#
将一个无界面的Python应用嵌入到
WPF
界面
中
,通过调整第三方窗口大小、查找窗口、设置父容器以及处理窗口标题,实现了美观的界面集成。同时,提供了当容器大小变化时,第三方窗口自适应大小的解决方案,确保了界面的流畅体验。此外,还解答了可能遇到的
问题
,如找不到
窗体
名称、
WPF
无Panel的替代方案等。
WPF
实现类似MDI子
窗体
的功能
本文介绍了在
WPF
中
实现类似MDI子
窗体
的功能。此前用UserControl作为“MDI子
窗体
”,现发现Extended
WPF
Toolkit里的ChildWindow可作子
窗体
。还给出实现步骤,包括下载开源免费的Community Edition,新建工程添加引用,在主
窗体
添加引用,用WindowContainer作子
窗体
容器等。
WPF
自定义
窗体
封装技术详解与实践
本文深入讲解在.NET的
WPF
框架
中
自定义
窗体
的封装过程。涵盖
WPF
基础架构理解、
自定义
窗体
类创建、XAML布局设计、代码逻辑与XAML绑定、样式与模板
使用
,以及
自定义
窗体
的实例化和
使用
,可帮助开发者打造个性化用户界面,增强功能定制性。
C#
111,129
社区成员
642,540
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章