首页 ZnWPF 文档 关于
左咛HIT
.net 开发热爱者
#桌面(WPF) #Web(asp.net) #领域驱动设计

从 winform 到 WPF 再到 asp.net ,这一切都使我获益良多。

QQ : 1176156504

微信 : s1176156504

邮箱 : zidream@foxmail.com

CustomWindow

所属程序集:ZnWpf.Presentation

描述

本控件为 WPF 原生 window 窗口的增强实现

具体为:

  • 保留了 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>

window

依赖属性 类型 默认值 描述
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 最大化功能按钮是否显示

依赖属性


TopAreaBackground

类型:Brush
默认值:#705d58
描述:用于设置窗体标题栏的背景颜色

演示

TopAreaForeground="#fdfbea"

tc 1

TopAreaBackground="#2d3e5c"

tc 2


TopAreaForeground

类型:Brush
默认值:White
描述:主要用于设置窗体的标题文字颜色

注意:由于触发器内无法使用绑定,该属性无法改变标题栏图标的颜色

演示

TopAreaForeground="#fdfbea"

tc 1

TopAreaBackground="#2d3e5c"

tc 2


TitleAlignment

类型:HorizontalAlignment
默认值:HorizontalAlignment.Left
描述:用于设置标题的显示位置,常用的靠左或居中

演示

TitleAlignment="Left"

tal

TitleAlignment="Center"

tac


IconHeight

类型:double
默认值:14
描述:用于设置标题图标的大小

演示

IconHeight="20"

ih 20


LeftCustomBlock

类型: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>

lcb


RightCustomBlock

类型: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>

rcb


WithIcon

类型:bool
默认值:True
描述:控制窗口图标是否显示

演示

WithIcon="True"  

wit

WithIcon="False"

wif


WithTopMost

类型:bool
默认值:False
描述:控制图钉功能按钮是否显示

演示

WithTopMost="True" 

wit

WithTopMost="False"

wtmf


WithMin

类型:bool
默认值:True
描述:控制最小化功能按钮是否显示

演示

WithMin="True"

wtmf

WithMin="False"

wminf


WithMax

类型:bool
默认值:True
描述:控制最大化功能按钮是否显示

演示

WithMax="True"  

wtmf

WithMax="False"

wmaxf