c# – 我可以在WPF中设置窗口边框颜色吗?

c# – 我可以在WPF中设置窗口边框颜色吗?,第1张

概述我可以知道如何设置窗口样式或颜色?下面的图片是我的 WPF 我想把我的窗口设置成下面的应用程序: 谢谢. 据我记得(4年以前),您可以创建一个使用WPF窗口的样式. 这是样例窗口样式: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 我可以知道如何设置窗口样式或颜色?下面的图片是我的 WPF

我想把我的窗口设置成下面的应用程序:

谢谢.

解决方法 据我记得(4年以前),您可以创建一个使用WPF窗口的样式.

这是样例窗口样式:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">     <Style x:Key="MainWindow"            targettype="{x:Type Window}">         <Setter Property="Foreground"                 Value="{DynamicResource {x:Static Systemcolors.WindowTextBrushKey}}" />         <Setter Property="Template">             <Setter.Value>                 <ControlTemplate targettype="{x:Type Window}">                     <GrID>                         <border x:name="Mainborder"                                 borderBrush="{DynamicResource MainWindowborderBrush}"                                 borderThickness="1"                                 CornerRadius="2"                                 Background="{DynamicResource MainWindowBackgroundBrush}">                             <DockPanel LastChildFill="True">                                 <Rectangle x:name="PART_left_border"                                            WIDth="2"                                            Cursor="SizeWE">                                     <Rectangle.Fill>                                         <SolIDcolorBrush color="transparent" />                                     </Rectangle.Fill>                                 </Rectangle>                                 <Rectangle x:name="PART_RIGHT_border"                                            Cursor="SizeWE"                                            WIDth="2"                                            DockPanel.Dock="Right">                                     <Rectangle.Fill>                                         <SolIDcolorBrush color="transparent" />                                     </Rectangle.Fill>                                 </Rectangle>                                 <Rectangle x:name="PART_top_border"                                            Cursor="SiZenS"                                            DockPanel.Dock="top"                                            Height="2">                                     <Rectangle.Fill>                                         <SolIDcolorBrush color="transparent" />                                     </Rectangle.Fill>                                 </Rectangle>                                 <Rectangle x:name="PART_BottOM_border"                                            Cursor="SiZenS"                                            Height="2"                                            DockPanel.Dock="Bottom">                                     <Rectangle.Fill>                                         <SolIDcolorBrush color="transparent" />                                     </Rectangle.Fill>                                 </Rectangle>                                 <border x:name="PART_Titlebar"                                         margin="2,2,2"                                         Height="40"                                         DockPanel.Dock="top"                                         CornerRadius="2"                                         Background="transparent">                                     <DockPanel LastChildFill="False">                                         <TextBlock margin="8,4"                                                    VerticalAlignment="Center"                                                    FontStretch="ultraExpanded"                                                    Foreground="Black"                                                    TextTrimming="CharacterEllipsis"                                                    textwrapPing="nowrap"                                                    Text="{TemplateBinding Title}"                                                    FontSize="16" />                                         <button x:name="PART_CLOSE"                                                 DockPanel.Dock="Right"                                                 Style="{DynamicResource Flatbutton}"                                                 VerticalAlignment="Center"                                                 margin="0,4,0">                                             <Image Source="/MixModes.Synergy.Resources;                        component/Resources/Close.png"                                                    Stretch="None"                                                    margin="4" />                                         </button>                                         <button x:name="PART_MAXIMIZE_RESTORE"                                                 DockPanel.Dock="Right"                                                 HorizontalAlignment="Center"                                                 VerticalAlignment="Center"                                                 Style="{DynamicResource Flatbutton}">                                             <Image x:name="MaximizeRestoreImage"                                                    Source="/MixModes.Synergy.Resources;                        component/Resources/Restore.png"                                                    Stretch="None"                                                    margin="4" />                                         </button>                                         <button x:name="PART_MINIMIZE"                                                 HorizontalAlignment="Center"                                                 Style="{DynamicResource Flatbutton}"                                                 VerticalAlignment="Center"                                                 DockPanel.Dock="Right">                                             <Image margin="4"                                                    Source="/MixModes.Synergy.                        Resources;component/Resources/                        Minimize.png"                                                    Stretch="None" />                                         </button>                                     </DockPanel>                                 </border>                                <!-- Title bar separator-->                                 <border Height="1"                                         DockPanel.Dock="top"                                         Background="{DynamicResource                     MainWindowTitlebarSeparator}" />                                <!-- Actual Window Content -->                                 <AdornerDecorator DockPanel.Dock="Bottom">                                     <ContentPresenter />                                 </AdornerDecorator>                             </DockPanel>                         </border>                     </GrID>                     <ControlTemplate.Triggers>                                                <DataTrigger Binding="{Binding relativeSource=                {relativeSource Self},Path=Maximized}"                                      Value="False">                             <Setter Targetname="MaximizeRestoreImage"                                     Property="Source"                                     Value="/MixModes.Synergy.Resources;                component/Resources/Maximize.png" />                         </DataTrigger>                     </ControlTemplate.Triggers>                 </ControlTemplate>             </Setter.Value>         </Setter>     </Style> </ResourceDictionary>@H_419_13@  

结果将如下所示:

阅读更多关于Create Custom Windows in WPF with Ease

总结

以上是内存溢出为你收集整理的c# – 我可以在WPF中设置窗口边框颜色吗?全部内容,希望文章能够帮你解决c# – 我可以在WPF中设置窗口边框颜色吗?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1237405.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存