新版自定义窗口标题栏样式基本完成
This commit is contained in:
@@ -8,9 +8,19 @@
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Icons\Icon.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Deedy.Activity\Deedy.Activity.csproj" />
|
||||
<ProjectReference Include="..\Deedy.Wpf\Deedy.Wpf.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Resource Include="Icons\Icon.png">
|
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||
</Resource>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
BIN
DeedyDesigner/Deedy.Testing/Icons/Icon.png
Normal file
BIN
DeedyDesigner/Deedy.Testing/Icons/Icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 204 B |
@@ -6,10 +6,14 @@
|
||||
xmlns:local="clr-namespace:Deedy.Testing"
|
||||
xmlns:deedy="clr-namespace:Deedy;assembly=Deedy.Wpf"
|
||||
mc:Ignorable="d"
|
||||
Title="WindowHeaderTest" Height="450" Width="800" Foreground="White">
|
||||
Title="WindowHeaderTest" Height="450" Width="800" Foreground="White" FontSize="18" d:WindowStyle="None" Icon="/Icons/Icon.png">
|
||||
<DockPanel>
|
||||
<deedy:WindowHeader>
|
||||
<deedy:WindowHeader ButtonBase.Click="WindowHeader_Click">
|
||||
<UniformGrid Rows="1">
|
||||
<Button Content="按钮"/>
|
||||
<Button Content="按钮"/>
|
||||
<Button Content="按钮"/>
|
||||
</UniformGrid>
|
||||
</deedy:WindowHeader>
|
||||
<Grid/>
|
||||
</DockPanel>
|
||||
|
||||
@@ -23,5 +23,10 @@ namespace Deedy.Testing
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void WindowHeader_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:Deedy">
|
||||
<Style TargetType="{x:Type local:WindowHeader}">
|
||||
<Setter Property="Height" Value="32"/>
|
||||
<Setter Property="Height" Value="40"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Left"/>
|
||||
<Setter Property="DockPanel.Dock" Value="Top"/>
|
||||
@@ -14,6 +14,7 @@
|
||||
<ControlTemplate.Resources>
|
||||
<Style x:Key="controlButtonStyle" TargetType="{x:Type Button}">
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="Cursor" Value="Hand"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type Button}">
|
||||
@@ -26,42 +27,27 @@
|
||||
</Style>
|
||||
</ControlTemplate.Resources>
|
||||
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
|
||||
<Grid x:Name="Root">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto"/>
|
||||
<ColumnDefinition Width="auto"/>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border x:Name="IconView" Width="{Binding ActualHeight, ElementName=Root}">
|
||||
<Image Margin="{TemplateBinding Padding}" VerticalAlignment="Center" HorizontalAlignment="Center"
|
||||
Source="{Binding Icon, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"/>
|
||||
</Border>
|
||||
<TextBlock x:Name="TitleBar" Grid.Column="1" FontSize="{TemplateBinding FontSize}" Foreground="{TemplateBinding Foreground}"
|
||||
Margin="{TemplateBinding Padding}" VerticalAlignment="Center" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
Text="{Binding Title, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"/>
|
||||
<Border x:Name="Container" Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
|
||||
<StackPanel x:Name="Controller" Grid.Column="3" Orientation="Horizontal">
|
||||
<Button x:Name="Minimize" VerticalAlignment="Stretch" Style="{StaticResource controlButtonStyle}" Cursor="Hand"
|
||||
Width="{Binding RelativeSource={RelativeSource Self},Path=ActualHeight}" Padding="{TemplateBinding Padding}">
|
||||
<Viewbox Stretch="Uniform">
|
||||
<Path Width="1024" Height="1024" Stroke="{TemplateBinding Foreground}" Fill="{TemplateBinding Foreground}" Data="M917.333333 554.666667H106.666667a21.333333 21.333333 0 0 1 0-42.666667h810.666666a21.333333 21.333333 0 0 1 0 42.666667z"/>
|
||||
</Viewbox>
|
||||
<DockPanel>
|
||||
<Image Margin="{TemplateBinding Padding}" Stretch="Uniform" Source="{Binding Icon, RelativeSource={RelativeSource AncestorType=Window}}"/>
|
||||
<TextBlock VerticalAlignment="Center" Margin="0,0,6,0" Text="{Binding Title, RelativeSource={RelativeSource AncestorType=Window}}"/>
|
||||
<DockPanel x:Name="Controller" DockPanel.Dock="Right" MinWidth="147" Background="#01FFFFFF" VerticalAlignment="Stretch">
|
||||
<Button x:Name="CloseWin" DockPanel.Dock="Right" Style="{DynamicResource controlButtonStyle}" Width="{Binding ActualHeight, RelativeSource={RelativeSource Self}}">
|
||||
<Path Stretch="Uniform" Margin="{TemplateBinding Padding}" Stroke="Transparent" Fill="{TemplateBinding Foreground}"
|
||||
Data="M 1 0 L 0 1 L 23 24 L 24 23 Z M 1 24 L 0 23 L 11 12 L 12 13 Z M 12 11 L 23 0 L 24 1 L 13 12 Z"/>
|
||||
</Button>
|
||||
<Button x:Name="Maximize" VerticalAlignment="Stretch" Style="{StaticResource controlButtonStyle}" Cursor="Hand"
|
||||
Width="{Binding RelativeSource={RelativeSource Self},Path=ActualHeight}" Padding="{TemplateBinding Padding}">
|
||||
<Viewbox Stretch="Uniform">
|
||||
<Path Width="1024" Height="1024" Stroke="{TemplateBinding Foreground}" Fill="{TemplateBinding Foreground}" Data="M714.666667 256H138.666667a53.393333 53.393333 0 0 0-53.333334 53.333333v576a53.393333 53.393333 0 0 0 53.333334 53.333334h576a53.393333 53.393333 0 0 0 53.333333-53.333334V309.333333a53.393333 53.393333 0 0 0-53.333333-53.333333z m10.666666 629.333333a10.666667 10.666667 0 0 1-10.666666 10.666667H138.666667a10.666667 10.666667 0 0 1-10.666667-10.666667V309.333333a10.666667 10.666667 0 0 1 10.666667-10.666666h576a10.666667 10.666667 0 0 1 10.666666 10.666666z m213.333334-746.666666v565.333333a21.333333 21.333333 0 0 1-42.666667 0V138.666667a10.666667 10.666667 0 0 0-10.666667-10.666667H320a21.333333 21.333333 0 0 1 0-42.666667h565.333333a53.393333 53.393333 0 0 1 53.333334 53.333334z"/>
|
||||
</Viewbox>
|
||||
<Button x:Name="Maximize" DockPanel.Dock="Right" Style="{DynamicResource controlButtonStyle}" Width="{Binding ActualHeight, RelativeSource={RelativeSource Self}}">
|
||||
<Path Stretch="Uniform" Margin="{TemplateBinding Padding}" Stroke="Transparent" Fill="{TemplateBinding Foreground}"
|
||||
Data="M 0 6 V 24 H 18 V 6 H 16.5 V 22.5 H 1.5 V 7.5 H 16.5 V 6 Z M 6 0 H 24 V 18 H 22.5 V 1.5 H 6 Z"/>
|
||||
</Button>
|
||||
<Button x:Name="CloseWin" VerticalAlignment="Stretch" Style="{StaticResource controlButtonStyle}" Cursor=""
|
||||
Width="{Binding RelativeSource={RelativeSource Self},Path=ActualHeight}" Padding="{TemplateBinding Padding}">
|
||||
<Viewbox Stretch="Uniform">
|
||||
<Path Width="1024" Height="1024" Stroke="{TemplateBinding Foreground}" Fill="{TemplateBinding Foreground}" Data="M542.173333 512l347.58-347.58a21.333333 21.333333 0 1 0-30.173333-30.173333L512 481.826667 164.42 134.246667a21.333333 21.333333 0 0 0-30.173333 30.173333L481.826667 512l-347.58 347.58a21.333333 21.333333 0 0 0 30.173333 30.173333L512 542.173333l347.58 347.58a21.333333 21.333333 0 0 0 30.173333-30.173333z"/>
|
||||
</Viewbox>
|
||||
|
||||
<Button x:Name="Minimize" DockPanel.Dock="Right" Style="{DynamicResource controlButtonStyle}" Width="{Binding ActualHeight, RelativeSource={RelativeSource Self}}">
|
||||
<Path Stretch="Uniform" Margin="{TemplateBinding Padding}" Stroke="Transparent" Fill="{TemplateBinding Foreground}"
|
||||
Data="M 0 0 V 24 M 0 11.25 V 12.75 H 24 V 11.25 Z"/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<Border/>
|
||||
</DockPanel>
|
||||
<Decorator x:Name="Container" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
|
||||
</DockPanel>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
|
||||
@@ -15,8 +15,6 @@ using System.Windows.Shell;
|
||||
namespace Deedy
|
||||
{
|
||||
[ContentProperty("Child")]
|
||||
[TemplatePart(Name = "IconView", Type = typeof(Border))]
|
||||
[TemplatePart(Name = "TitleBar", Type = typeof(TextBlock))]
|
||||
[TemplatePart(Name = "Minimize", Type = typeof(Button))]
|
||||
[TemplatePart(Name = "Maximize", Type = typeof(Button))]
|
||||
[TemplatePart(Name = "CloseWin", Type = typeof(Button))]
|
||||
@@ -61,8 +59,6 @@ namespace Deedy
|
||||
private Button? Minimize;
|
||||
private Button? Maximize;
|
||||
private Button? CloseWin;
|
||||
private TextBlock? TitleBar;
|
||||
private Border? IconView;
|
||||
|
||||
private Window? Target;
|
||||
private WindowChrome? Chrome;
|
||||
@@ -102,8 +98,7 @@ namespace Deedy
|
||||
this.Minimize = GetTemplateChild("Minimize") as Button;
|
||||
this.Maximize = GetTemplateChild("Maximize") as Button;
|
||||
this.CloseWin = GetTemplateChild("CloseWin") as Button;
|
||||
this.IconView = GetTemplateChild("IconView") as Border;
|
||||
this.TitleBar = GetTemplateChild("TitleBar") as TextBlock;
|
||||
|
||||
if (this.Container != null) this.Container.Child = this.Child;
|
||||
}
|
||||
private void Target_Loaded(object sender, RoutedEventArgs e)
|
||||
@@ -115,6 +110,7 @@ namespace Deedy
|
||||
WindowChrome.SetWindowChrome(this.Target, this.Chrome);
|
||||
WindowChrome.SetIsHitTestVisibleInChrome(this.Container, true);
|
||||
WindowChrome.SetIsHitTestVisibleInChrome(this.Controller, true);
|
||||
|
||||
if (this.Controller != null)
|
||||
{
|
||||
foreach (var c in this.Controller.Children)
|
||||
@@ -140,12 +136,11 @@ namespace Deedy
|
||||
{
|
||||
if (this.Target != null)
|
||||
{
|
||||
this.Visibility = Visibility.Visible;
|
||||
if (this.Controller != null) this.Controller.Visibility = Visibility.Visible;
|
||||
if (this.Minimize != null) this.Minimize.Visibility = Visibility.Visible;
|
||||
if (this.Maximize != null) this.Maximize.Visibility = Visibility.Visible;
|
||||
if (this.CloseWin != null) this.CloseWin.Visibility = Visibility.Visible;
|
||||
if (this.IconView != null) this.IconView.Visibility = Visibility.Visible;
|
||||
if (this.TitleBar != null) this.TitleBar.Visibility = Visibility.Visible;
|
||||
|
||||
if (this.Target.ResizeMode == ResizeMode.NoResize)
|
||||
{
|
||||
@@ -158,9 +153,7 @@ namespace Deedy
|
||||
}
|
||||
if (this.Target.WindowStyle == WindowStyle.None)
|
||||
{
|
||||
if (this.IconView != null) this.IconView.Visibility = Visibility.Collapsed;
|
||||
if (this.TitleBar != null) this.TitleBar.Visibility = Visibility.Collapsed;
|
||||
if (this.Controller != null) this.Controller.Visibility = Visibility.Collapsed;
|
||||
this.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
if (this.Target.WindowStyle == WindowStyle.ToolWindow)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user