Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ItemMinWidth and TopLevelMinWidth for MenuAttach. #1595

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 96 additions & 34 deletions src/Shared/HandyControlDemo_Shared/UserControl/Styles/MenuDemoCtl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,101 @@
xmlns:ex="clr-namespace:HandyControlDemo.Tools.Extension"
Background="{DynamicResource RegionBrush}">
<hc:TransitioningContentControl>
<hc:UniformSpacingPanel Spacing="16" Margin="32">
<hc:DashedBorder Width="200" Height="112" Background="Transparent" CornerRadius="4" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1" BorderDashArray="2,2">
<hc:DashedBorder.ContextMenu>
<ContextMenu ItemsSource="{Binding DataList}">
<ContextMenu.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding DataList}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
</ContextMenu.ItemTemplate>
</ContextMenu>
</hc:DashedBorder.ContextMenu>
<TextBlock Foreground="{DynamicResource BorderBrush}" Style="{StaticResource TextBlockTitle}" TextAlignment="Center">
<Run Text="{ex:Lang Key={x:Static langs:LangKeys.RightClickHere}}"/>
<LineBreak />
<Run Text="Default" />
</TextBlock>
</hc:DashedBorder>
<hc:DashedBorder Width="200" Height="112" Background="Transparent" CornerRadius="4" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1" BorderDashArray="2,2">
<hc:DashedBorder.ContextMenu>
<ContextMenu ItemsSource="{Binding DataList}" Style="{StaticResource ContextMenu.Small}">
<ContextMenu.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding DataList}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
</ContextMenu.ItemTemplate>
</ContextMenu>
</hc:DashedBorder.ContextMenu>
<TextBlock Foreground="{DynamicResource BorderBrush}" Style="{StaticResource TextBlockTitle}" TextAlignment="Center">
<Run Text="{ex:Lang Key={x:Static langs:LangKeys.RightClickHere}}" />
<LineBreak />
<Run Text="Small" />
</TextBlock>
</hc:DashedBorder>
</hc:UniformSpacingPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>

<Menu Grid.Row="0" ItemsSource="{Binding DataList}" Margin="32">
<Menu.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding DataList}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
</Menu.ItemTemplate>
</Menu>

<Menu Grid.Row="1" ItemsSource="{Binding DataList}" Margin="32"
hc:MenuAttach.TopLevelMinWidth="100" hc:MenuAttach.ItemMinWidth="0">
<Menu.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding DataList}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
</Menu.ItemTemplate>
</Menu>

<hc:UniformSpacingPanel Spacing="16" Margin="32" Grid.Row="2">

<hc:DashedBorder Width="200" Height="112" Background="Transparent" CornerRadius="4" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1" BorderDashArray="2,2">
<hc:DashedBorder.ContextMenu>
<ContextMenu ItemsSource="{Binding DataList}">
<ContextMenu.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding DataList}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
</ContextMenu.ItemTemplate>
</ContextMenu>
</hc:DashedBorder.ContextMenu>
<TextBlock Foreground="{DynamicResource BorderBrush}" Style="{StaticResource TextBlockTitle}" TextAlignment="Center">
<Run Text="{ex:Lang Key={x:Static langs:LangKeys.RightClickHere}}"/>
<LineBreak />
<Run Text="Default" />
</TextBlock>
</hc:DashedBorder>
<hc:DashedBorder Width="200" Height="112" Background="Transparent" CornerRadius="4" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1" BorderDashArray="2,2">
<hc:DashedBorder.ContextMenu>
<ContextMenu ItemsSource="{Binding DataList}" Style="{StaticResource ContextMenu.Small}">
<ContextMenu.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding DataList}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
</ContextMenu.ItemTemplate>
</ContextMenu>
</hc:DashedBorder.ContextMenu>
<TextBlock Foreground="{DynamicResource BorderBrush}" Style="{StaticResource TextBlockTitle}" TextAlignment="Center">
<Run Text="{ex:Lang Key={x:Static langs:LangKeys.RightClickHere}}" />
<LineBreak />
<Run Text="Small" />
</TextBlock>
</hc:DashedBorder>
<hc:DashedBorder Width="200" Height="112" Background="Transparent" CornerRadius="4" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1" BorderDashArray="2,2">
<hc:DashedBorder.ContextMenu>
<ContextMenu ItemsSource="{Binding DataList}" hc:MenuAttach.ItemMinWidth="0">
<ContextMenu.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding DataList}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
</ContextMenu.ItemTemplate>
</ContextMenu>
</hc:DashedBorder.ContextMenu>
<TextBlock Foreground="{DynamicResource BorderBrush}" Style="{StaticResource TextBlockTitle}" TextAlignment="Center">
<Run Text="{ex:Lang Key={x:Static langs:LangKeys.RightClickHere}}"/>
<LineBreak />
<Run Text="Default" />
<LineBreak />
<Run Text="ItemMinWidth" />
</TextBlock>
</hc:DashedBorder>
<hc:DashedBorder Width="200" Height="112" Background="Transparent" CornerRadius="4" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1" BorderDashArray="2,2">
<hc:DashedBorder.ContextMenu>
<ContextMenu ItemsSource="{Binding DataList}" hc:MenuAttach.ItemMinWidth="0" Style="{StaticResource ContextMenu.Small}">
<ContextMenu.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding DataList}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
</ContextMenu.ItemTemplate>
</ContextMenu>
</hc:DashedBorder.ContextMenu>
<TextBlock Foreground="{DynamicResource BorderBrush}" Style="{StaticResource TextBlockTitle}" TextAlignment="Center">
<Run Text="{ex:Lang Key={x:Static langs:LangKeys.RightClickHere}}" />
<LineBreak />
<Run Text="Small" />
<LineBreak />
<Run Text="ItemMinWidth" />
</TextBlock>
</hc:DashedBorder>
</hc:UniformSpacingPanel>
</Grid>
</hc:TransitioningContentControl>
</UserControl>
14 changes: 14 additions & 0 deletions src/Shared/HandyControl_Shared/Controls/Attach/MenuAttach.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,18 @@ public static void SetItemPadding(DependencyObject element, Thickness value)

public static Thickness GetItemPadding(DependencyObject element)
=> (Thickness) element.GetValue(ItemPaddingProperty);

public static readonly DependencyProperty ItemMinWidthProperty = DependencyProperty.RegisterAttached(
"ItemMinWidth", typeof(double), typeof(MenuAttach), new PropertyMetadata(ValueBoxes.Double240Box));

public static void SetItemMinWidth(DependencyObject obj, double value) => obj.SetValue(ItemMinWidthProperty, value);

public static double GetItemMinWidth(DependencyObject obj) => (double) obj.GetValue(ItemMinWidthProperty);

public static readonly DependencyProperty TopLevelMinWidthProperty = DependencyProperty.RegisterAttached(
"TopLevelMinWidth", typeof(double), typeof(MenuAttach), new PropertyMetadata(ValueBoxes.Double44Box));

public static void SetTopLevelMinWidth(DependencyObject obj, double value) => obj.SetValue(TopLevelMinWidthProperty, value);

public static double GetTopLevelMinWidth(DependencyObject obj) => (double) obj.GetValue(TopLevelMinWidthProperty);
}
4 changes: 4 additions & 0 deletions src/Shared/HandyControl_Shared/Data/ValueBoxes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ internal static class ValueBoxes

internal static object Double20Box = 20.0;

internal static object Double44Box = 44.0;

internal static object Double100Box = 100.0;

internal static object Double200Box = 200.0;

internal static object Double240Box = 240.0;

internal static object Double300Box = 300.0;

internal static object DoubleNeg1Box = -1.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="MenuItem">
<Border x:Name="Bd" CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" MinWidth="240" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Border x:Name="Bd" CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" MinWidth="{Binding Path=(hc:MenuAttach.ItemMinWidth), RelativeSource={RelativeSource AncestorType=MenuBase}}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Grid x:Name="Grid" Margin="{TemplateBinding Padding}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="26"/>
Expand Down Expand Up @@ -49,7 +49,7 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="MenuItem">
<Border MinWidth="44" x:Name="templateRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1,1,1,0" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Border MinWidth="{Binding Path=(hc:MenuAttach.TopLevelMinWidth), RelativeSource={RelativeSource AncestorType=MenuBase}}" x:Name="templateRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1,1,1,0" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Grid VerticalAlignment="Center" Margin="{TemplateBinding Padding}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
Expand Down Expand Up @@ -147,7 +147,7 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="MenuItem">
<Border x:Name="Bd" CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" MinWidth="240" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Border x:Name="Bd" CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" MinWidth="{Binding Path=(hc:MenuAttach.ItemMinWidth), RelativeSource={RelativeSource AncestorType=MenuBase}}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Grid x:Name="Grid" Margin="{TemplateBinding Padding}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="26"/>
Expand Down