从 winform 到 WPF 再到 asp.net ,这一切都使我获益良多。
QQ : 1176156504
微信 : s1176156504
邮箱 : zidream@foxmail.com
所属程序集:ZnWpf.Presentation
本控件为 WPF 原生 window 窗口的增强实现
具体为:
<controls:CustomWindow x:Class="ZnWpf.Presentation.Test.CustomWindowTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ZnWpf.Presentation.Test"
mc:Ignorable="d"
xmlns:controls="clr-namespace:ZnWpf.Presentation.Controls;assembly=ZnWpf.Presentation"
Title="CustomWindowTest" TopAreaBackground="#705d58" TopAreaForeground="White" TitleAlignment="Left" IconHeight="14" WithIcon="True" WithTopMost="False" WithMin="True" WithMax="True" Height="450" Width="800">
<controls:CustomWindow.LeftCustomBlock>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
</StackPanel>
</controls:CustomWindow.LeftCustomBlock>
<controls:CustomWindow.RightCustomBlock>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
</StackPanel>
</controls:CustomWindow.RightCustomBlock>
<Grid>
</Grid>
</controls:CustomWindow>
依赖属性 | 类型 | 默认值 | 描述 |
---|---|---|---|
TopAreaBackground | Brush | #705d58 | 标题栏的背景颜色 |
TopAreaForeground | Brush | White | 标题文字颜色 |
TitleAlignment | HorizontalAlignment | HorizontalAlignment.Left | 标题的显示位置 |
IconHeight | double | 14 | 标题图标的大小 |
LeftCustomBlock | Panel | null | 标题栏左扩展区域 |
RightCustomBlock | Panel | null | 标题栏右扩展区域 |
WithIcon | bool | True | 窗口图标是否显示 |
WithTopMost | bool | False | 图钉功能按钮是否显示 |
WithMin | bool | True | 最小化功能按钮是否显示 |
WithMax | bool | True | 最大化功能按钮是否显示 |
类型:Brush
默认值:#705d58
描述:用于设置窗体标题栏的背景颜色
TopAreaForeground="#fdfbea"
TopAreaBackground="#2d3e5c"
类型:Brush
默认值:White
描述:主要用于设置窗体的标题文字颜色
注意:由于触发器内无法使用绑定,该属性无法改变标题栏图标的颜色
TopAreaForeground="#fdfbea"
TopAreaBackground="#2d3e5c"
类型:HorizontalAlignment
默认值:HorizontalAlignment.Left
描述:用于设置标题的显示位置,常用的靠左或居中
TitleAlignment="Left"
TitleAlignment="Center"
类型:double
默认值:14
描述:用于设置标题图标的大小
IconHeight="20"
类型:Panel
默认值:null
描述:标题栏的左扩展区域,位置在窗口图标和标题文字之间,可以放置panel的任何子类,比如 Grid,StackPanel
小技巧:或许你可以选择不显示窗口图标和标题文字,而在 LeftCustomBlock 中自行实现
<controls:CustomWindow x:Class="ZnWpf.Presentation.Test.CustomWindowTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ZnWpf.Presentation.Test"
mc:Ignorable="d"
xmlns:controls="clr-namespace:ZnWpf.Presentation.Controls;assembly=ZnWpf.Presentation"
Title="CustomWindowTest" WithTopMost="True" Height="450" Width="800">
<controls:CustomWindow.LeftCustomBlock>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock Foreground="White" Text="你可以放一些文字" Margin="5 0" VerticalAlignment="Center"></TextBlock>
<Button Margin="5 0" Padding="5 2" Content="或者按钮" VerticalAlignment="Center"></Button>
</StackPanel>
</controls:CustomWindow.LeftCustomBlock>
<Grid>
</Grid>
</controls:CustomWindow>
类型:Panel
默认值:null
描述:标题栏的右扩展区域,位置在窗口功能按钮的左侧,可以放置panel的任何子类,比如 Grid,StackPanel
<controls:CustomWindow x:Class="ZnWpf.Presentation.Test.CustomWindowTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ZnWpf.Presentation.Test"
mc:Ignorable="d"
xmlns:controls="clr-namespace:ZnWpf.Presentation.Controls;assembly=ZnWpf.Presentation"
Title="CustomWindowTest" WithTopMost="True" Height="450" Width="800">
<controls:CustomWindow.RightCustomBlock>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock Foreground="White" Text="你可以放一些文字" Margin="5 0" VerticalAlignment="Center"></TextBlock>
<Button Margin="5 0" Padding="5 2" Content="或者按钮" VerticalAlignment="Center"></Button>
</StackPanel>
</controls:CustomWindow.RightCustomBlock>
<Grid>
</Grid>
</controls:CustomWindow>
类型:bool
默认值:True
描述:控制窗口图标是否显示
WithIcon="True"
WithIcon="False"
类型:bool
默认值:False
描述:控制图钉功能按钮是否显示
WithTopMost="True"
WithTopMost="False"
类型:bool
默认值:True
描述:控制最小化功能按钮是否显示
WithMin="True"
WithMin="False"
类型:bool
默认值:True
描述:控制最大化功能按钮是否显示
WithMax="True"
WithMax="False"