1. Fixed a bug of WindowBorderless, when the SizeToContent property is set to a value, a black area will be display;

2. Some styles have been modified, including button, menu and popupwindow
This commit is contained in:
NaBian 2018-09-18 13:49:11 +08:00
parent e6cab06d05
commit c4a68fc013
7 changed files with 46 additions and 31 deletions

View File

@ -1,12 +1,14 @@
<Window x:Class="HandyControl.Controls.PopupWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:HandyControl.Controls"
WindowStyle="None"
Name="MyWindow"
MinHeight="190"
MinHeight="220"
xmlns:langs="clr-namespace:HandyControl.Properties.Langs"
BorderThickness="20"
ShowInTaskbar="False"
MinWidth="240"
MinWidth="300"
UseLayoutRounding="True"
ResizeMode="NoResize"
SizeToContent="WidthAndHeight">
@ -31,25 +33,25 @@
<Grid Name="TitleGrid" Height="30" Background="{DynamicResource PrimaryBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="36"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Name="TitleBlock" Background="Transparent" MouseLeftButtonDown="TitleBlock_OnMouseLeftButtonDown" Padding="10,6" FontSize="14" Foreground="White" Text="{Binding Title,ElementName=MyWindow}" VerticalAlignment="Center" TextWrapping="Wrap" TextTrimming="WordEllipsis"/>
<Button Grid.Column="1" Click="CloseButton_OnClick" IsCancel="True" Name="CloseButton" Width="20" Height="20" Style="{StaticResource ButtonOpacityStyle}" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,5,8,0" Background="Transparent" Foreground="White">
<Path Fill="{Binding ElementName=CloseButton,Path=Foreground}" Width="16" Height="16" Style="{StaticResource ClosePathStyle}"/>
<Button Foreground="White" Grid.Column="1" controls:BackgroundSwitchElement.MouseHoverBackground="Red" controls:BackgroundSwitchElement.MouseDownBackground="Red" Click="CloseButton_OnClick" IsCancel="True" Name="CloseButton" IsTabStop="False" WindowChrome.IsHitTestVisibleInChrome="True" Height="28" Style="{StaticResource ButtonOpacityStyle}" Width="44" controls:IconElement.Geometry="{StaticResource CloseGeometry}" Padding="9">
<Path Fill="{Binding ElementName=CloseButton,Path=Foreground}" Style="{StaticResource ClosePathStyle}"/>
</Button>
</Grid>
<Border BorderBrush="{DynamicResource PrimaryBrush}" Name="MainBorder" Grid.Row="1">
<StackPanel>
<TextBlock Text="" MinHeight="80" Name="MyTextBlock" TextAlignment="Center" FontSize="16" Padding="10" Foreground="#252525" MaxWidth="300" TextWrapping="Wrap" TextTrimming="CharacterEllipsis" Background="White"/>
<StackPanel Name="MyStackPanel" Visibility="Visible" Margin="0,0,0,10" Orientation="Horizontal" Background="White" HorizontalAlignment="Center">
<Button Name="ButtonCancle" Visibility="{Binding ShowCancel,ElementName=MyWindow,Converter={StaticResource Boolean2VisibilityConverter}}" Click="ButtonCancle_OnClick" Margin="10,0" Background="Transparent" Height="30" Width="60" Style="{StaticResource ButtonOpacityStyle}">
<Border BorderThickness="1" BorderBrush="{DynamicResource PrimaryBrush}" Width="60" Height="30" CornerRadius="4" Background="White">
<TextBlock FontSize="16" Text="取消" Foreground="{DynamicResource PrimaryBrush}" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
<TextBlock Text="" MinHeight="110" Name="MyTextBlock" TextAlignment="Center" FontSize="16" Padding="32" Foreground="#252525" MaxWidth="300" TextWrapping="Wrap" TextTrimming="CharacterEllipsis" Background="White"/>
<StackPanel Name="MyStackPanel" Margin="0,0,0,32" Orientation="Horizontal" Background="White" HorizontalAlignment="Center">
<Button Name="ButtonCancle" Visibility="{Binding ShowCancel,ElementName=MyWindow,Converter={StaticResource Boolean2VisibilityConverter}}" Click="ButtonCancle_OnClick" Margin="0,0,16,0" Background="Transparent" Style="{StaticResource ButtonOpacityStyle}">
<Border BorderThickness="1" BorderBrush="{DynamicResource PrimaryBrush}" MinWidth="80" Height="30" CornerRadius="4" Background="White">
<TextBlock FontSize="16" Text="{x:Static langs:Lang.Cancel}" Foreground="{DynamicResource PrimaryBrush}" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
</Border>
</Button>
<Button IsDefault="True" Click="ButtonOk_OnClick" Margin="10,0" Background="Transparent" Height="30" Width="60" Style="{DynamicResource ButtonOpacityStyle}">
<Border Width="60" Height="30" CornerRadius="4" Background="{DynamicResource PrimaryBrush}">
<TextBlock FontSize="16" Text="确定" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
<Button IsDefault="True" Click="ButtonOk_OnClick" Background="Transparent" Style="{DynamicResource ButtonOpacityStyle}">
<Border MinWidth="80" Height="30" CornerRadius="4" Background="{DynamicResource PrimaryBrush}">
<TextBlock FontSize="16" Text="{x:Static langs:Lang.Confirm}" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
</Border>
</Button>
</StackPanel>

View File

@ -45,14 +45,7 @@ namespace HandyControl.Controls
public UIElement Child
{
get => MainBorder.Child;
set
{
MainBorder.Child = value;
if (value is FrameworkElement temp)
{
TitleBlock.Width = temp.Width - 40;
}
}
set => MainBorder.Child = value;
}
public bool ShowTitle

View File

@ -120,6 +120,17 @@ namespace HandyControl.Controls
}
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
if (SizeToContent != SizeToContent.WidthAndHeight)
return;
SizeToContent = SizeToContent.Height;
Dispatcher.BeginInvoke(new Action(() => { SizeToContent = SizeToContent.WidthAndHeight; }));
}
public Brush CloseButtonForeground
{
get => (Brush)GetValue(CloseButtonForegroundProperty);

View File

@ -10,5 +10,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("1.2.1.1")]
[assembly: AssemblyFileVersion("1.2.1.1")]
[assembly: AssemblyVersion("1.2.1.2")]
[assembly: AssemblyFileVersion("1.2.1.2")]

View File

@ -16,6 +16,8 @@
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="IsTabStop" Value="False"></Setter>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Focusable" Value="False"/>
</Style>
</ResourceDictionary>

View File

@ -2,6 +2,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:HandyControl.Controls">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../../Basic/Geometries.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<!--普通菜单项-->
<Style x:Key="MenuItemBaseStyle" TargetType="{x:Type MenuItem}">
<Setter Property="OverridesDefaultStyle" Value="True"/>
@ -61,11 +65,14 @@
</Border>
<ContentPresenter x:Name="menuHeaderContainer" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Grid.Column="1" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
<Popup Grid.Column="0" x:Name="PART_Popup" PlacementTarget="{Binding ElementName=templateRoot}" AllowsTransparency="True" Focusable="False" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Bottom">
<Border CornerRadius="0,0,2,2" x:Name="SubMenuBorder" BorderThickness="1,0,1,1" BorderBrush="{DynamicResource BorderBrush}" Background="White">
<Grid>
<Border CornerRadius="0,0,2,2" x:Name="SubMenuBorder" BorderThickness="1" BorderBrush="{DynamicResource BorderBrush}" Background="White">
<controls:ScrollViewer VerticalScrollBarVisibility="Auto" x:Name="SubMenuScrollViewer" Margin="0,6">
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Cycle" Grid.IsSharedSizeScope="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/>
</controls:ScrollViewer>
</Border>
<Border Height="1" Background="White" VerticalAlignment="Top" BorderThickness="1,0" BorderBrush="{DynamicResource BorderBrush}" HorizontalAlignment="Left" Width="{Binding ActualWidth,ElementName=templateRoot}"></Border>
</Grid>
</Popup>
</Grid>
</Border>
@ -81,7 +88,7 @@
<Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/>
</Trigger>
<Trigger Property="IsHighlighted" Value="True">
<Setter Property="Background" TargetName="templateRoot" Value="White"/>
<Setter Property="Background" TargetName="templateRoot" Value="WhiteSmoke"/>
<Setter Property="TextElement.Foreground" TargetName="menuHeaderContainer" Value="{DynamicResource PrimaryTextBrush}"/>
</Trigger>
<Trigger Property="IsSubmenuOpen" Value="True">

View File

@ -12,5 +12,5 @@ using System.Windows;
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
[assembly: AssemblyVersion("1.2.1.1")]
[assembly: AssemblyFileVersion("1.2.1.1")]
[assembly: AssemblyVersion("1.2.1.2")]
[assembly: AssemblyFileVersion("1.2.1.2")]