add SplitButton
This commit is contained in:
1 parent
61c5044b6f
commit
e5029aa5dd
12 files changed
+34
-87
No files matched your search
@@ -63,6 +63,10 @@ Step 4:enjoy coding
|
||||
|
||||
## Latest examples
|
||||
|
||||
### SplitButton
|
||||
|
||||

|
||||
|
||||
### FloatingBlock
|
||||
|
||||

|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Basic\ChatBox.xaml.cs">
|
||||
<DependentUpon>ChatBox.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Basic\CustomSplitButtonItem.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Basic\IFull.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Basic\InteractiveDialog.xaml.cs">
|
||||
<DependentUpon>InteractiveDialog.xaml</DependentUpon>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
xmlns:userControl="clr-namespace:HandyControlDemo.UserControl">
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol">
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="../Basic/Geometries.xaml"/>
|
||||
@@ -99,6 +98,4 @@
|
||||
<Setter Property="Padding" Value="25"/>
|
||||
</Style>
|
||||
|
||||
<Style BasedOn="{StaticResource ComboBoxItemBaseStyle}" TargetType="userControl:CustomSplitButtonItem"/>
|
||||
|
||||
</ResourceDictionary>
|
||||
@@ -1,10 +0,0 @@
|
||||
using System.Windows.Controls;
|
||||
using HandyControl.Controls;
|
||||
|
||||
namespace HandyControlDemo.UserControl
|
||||
{
|
||||
public class CustomSplitButtonItem : ComboBoxItem, ISplitButtonItem
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,39 +7,30 @@
|
||||
DataContext="{Binding SplitButtonDemo,Source={StaticResource Locator}}">
|
||||
<hc:TransitioningContentControl>
|
||||
<StackPanel Margin="32" VerticalAlignment="Center">
|
||||
<hc:SplitButton Margin="0,0,0,10" Content="{x:Static langs:Lang.Default}" Command="{Binding SelectCmd}" CommandParameter="Command0">
|
||||
<hc:SplitButton Margin="0,0,0,10" Content="{x:Static langs:Lang.Default}" Command="{Binding SelectCmd}" CommandParameter="Command0" HorizontalAlignment="Stretch">
|
||||
<hc:SplitButton.DropDownContent>
|
||||
<StackPanel>
|
||||
<hc:SplitButtonItem Header="{x:Static langs:Lang.Title}" Command="{Binding SelectCmd}" CommandParameter="Command1"/>
|
||||
<hc:SplitButtonItem Header="{x:Static langs:Lang.Title}" Command="{Binding SelectCmd}" CommandParameter="Command2"/>
|
||||
<hc:SplitButtonItem Header="{x:Static langs:Lang.Title}" Command="{Binding SelectCmd}" CommandParameter="Command3"/>
|
||||
<MenuItem Header="{x:Static langs:Lang.Title}" Command="{Binding SelectCmd}" CommandParameter="Command1"/>
|
||||
<MenuItem Header="{x:Static langs:Lang.Title}" Command="{Binding SelectCmd}" CommandParameter="Command2"/>
|
||||
<MenuItem Header="{x:Static langs:Lang.Title}" Command="{Binding SelectCmd}" CommandParameter="Command3"/>
|
||||
</StackPanel>
|
||||
</hc:SplitButton.DropDownContent>
|
||||
</hc:SplitButton>
|
||||
<hc:SplitButton Style="{StaticResource SplitButtonPrimary}" Margin="0,0,0,10" Content="{x:Static langs:Lang.Default}" Command="{Binding SelectCmd}" CommandParameter="Command0">
|
||||
<hc:SplitButton Style="{StaticResource SplitButtonPrimary}" Margin="0,0,0,10" Content="{x:Static langs:Lang.Primary}" Command="{Binding SelectCmd}" CommandParameter="Command0" HorizontalAlignment="Stretch">
|
||||
<hc:SplitButton.DropDownContent>
|
||||
<StackPanel>
|
||||
<hc:SplitButtonItem Header="{x:Static langs:Lang.Title}" Command="{Binding SelectCmd}" CommandParameter="Command1"/>
|
||||
<hc:SplitButtonItem Header="{x:Static langs:Lang.Title}" Command="{Binding SelectCmd}" CommandParameter="Command2"/>
|
||||
<hc:SplitButtonItem Header="{x:Static langs:Lang.Title}" Command="{Binding SelectCmd}" CommandParameter="Command3"/>
|
||||
<MenuItem Header="{x:Static langs:Lang.Title}" Command="{Binding SelectCmd}" CommandParameter="Command1"/>
|
||||
<MenuItem Header="{x:Static langs:Lang.Title}" Command="{Binding SelectCmd}" CommandParameter="Command2"/>
|
||||
<MenuItem Header="{x:Static langs:Lang.Title}" Command="{Binding SelectCmd}" CommandParameter="Command3"/>
|
||||
</StackPanel>
|
||||
</hc:SplitButton.DropDownContent>
|
||||
</hc:SplitButton>
|
||||
<hc:SplitButton Margin="0,0,0,10" Content="{x:Static langs:Lang.Default}" HitMode="Hover">
|
||||
<hc:SplitButton Style="{StaticResource SplitButtonWarning}" Margin="0,0,0,10" Content="{x:Static langs:Lang.Warning}" HitMode="Hover" HorizontalAlignment="Stretch">
|
||||
<hc:SplitButton.DropDownContent>
|
||||
<StackPanel>
|
||||
<hc:SplitButtonItem Header="{x:Static langs:Lang.Title}" Command="{Binding SelectCmd}" CommandParameter="Command1"/>
|
||||
<hc:SplitButtonItem Header="{x:Static langs:Lang.Title}" Command="{Binding SelectCmd}" CommandParameter="Command2"/>
|
||||
<hc:SplitButtonItem Header="{x:Static langs:Lang.Title}" Command="{Binding SelectCmd}" CommandParameter="Command3"/>
|
||||
</StackPanel>
|
||||
</hc:SplitButton.DropDownContent>
|
||||
</hc:SplitButton>
|
||||
<hc:SplitButton Margin="0,0,0,10" Content="{x:Static langs:Lang.Default}" HitMode="Hover">
|
||||
<hc:SplitButton.DropDownContent>
|
||||
<StackPanel>
|
||||
<userControl:CustomSplitButtonItem Content="{x:Static langs:Lang.Title}"/>
|
||||
<userControl:CustomSplitButtonItem Content="{x:Static langs:Lang.Title}"/>
|
||||
<userControl:CustomSplitButtonItem Content="{x:Static langs:Lang.Title}"/>
|
||||
<MenuItem Header="{x:Static langs:Lang.Title}" Command="{Binding SelectCmd}" CommandParameter="Command1"/>
|
||||
<MenuItem Header="{x:Static langs:Lang.Title}" Command="{Binding SelectCmd}" CommandParameter="Command2"/>
|
||||
<MenuItem Header="{x:Static langs:Lang.Title}" Command="{Binding SelectCmd}" CommandParameter="Command3"/>
|
||||
</StackPanel>
|
||||
</hc:SplitButton.DropDownContent>
|
||||
</hc:SplitButton>
|
||||
|
||||
@@ -101,13 +101,13 @@ namespace HandyControl.Controls
|
||||
{
|
||||
if (!(d is UIElement target)) return;
|
||||
|
||||
target.RemoveHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(Target_PreviewMouseLeftButtonDown));
|
||||
target.RemoveHandler(PreviewMouseLeftButtonUpEvent, new MouseButtonEventHandler(Target_PreviewMouseLeftButtonUp));
|
||||
target.PreviewMouseLeftButtonDown -= Target_PreviewMouseLeftButtonDown;
|
||||
target.PreviewMouseLeftButtonUp -= Target_PreviewMouseLeftButtonUp;
|
||||
|
||||
if (e.NewValue != null)
|
||||
{
|
||||
target.AddHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(Target_PreviewMouseLeftButtonDown));
|
||||
target.AddHandler(PreviewMouseLeftButtonUpEvent, new MouseButtonEventHandler(Target_PreviewMouseLeftButtonUp));
|
||||
target.PreviewMouseLeftButtonDown += Target_PreviewMouseLeftButtonDown;
|
||||
target.PreviewMouseLeftButtonUp += Target_PreviewMouseLeftButtonUp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-17
@@ -7,13 +7,8 @@ using HandyControl.Data.Enum;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
[TemplatePart(Name = ElementArrow, Type = typeof(ToggleButton))]
|
||||
public class SplitButton : ButtonBase
|
||||
{
|
||||
private const string ElementArrow = "PART_Arrow";
|
||||
|
||||
private ToggleButton _toggleArrow;
|
||||
|
||||
public static readonly DependencyProperty HitModeProperty = DependencyProperty.Register(
|
||||
"HitMode", typeof(MouseHitMode), typeof(SplitButton), new PropertyMetadata(default(MouseHitMode)));
|
||||
|
||||
@@ -55,18 +50,11 @@ namespace HandyControl.Controls
|
||||
AddHandler(MenuItem.ClickEvent, new RoutedEventHandler(ItemsOnClick));
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
|
||||
_toggleArrow = GetTemplateChild(ElementArrow) as ToggleButton;
|
||||
}
|
||||
|
||||
private void ItemsOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (e.OriginalSource is ISplitButtonItem)
|
||||
if (e.OriginalSource is MenuItem)
|
||||
{
|
||||
SetCurrentValue(IsDropDownOpenProperty, false);
|
||||
SetCurrentValue(IsDropDownOpenProperty, ValueBoxes.FalseBox);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,10 +66,15 @@ namespace HandyControl.Controls
|
||||
{
|
||||
e.Handled = true;
|
||||
}
|
||||
else if (_toggleArrow != null && _toggleArrow.IsMouseOver)
|
||||
}
|
||||
|
||||
protected override void OnMouseEnter(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseEnter(e);
|
||||
|
||||
if (HitMode == MouseHitMode.Hover)
|
||||
{
|
||||
SetCurrentValue(IsDropDownOpenProperty, _toggleArrow.IsChecked != true);
|
||||
e.Handled = true;
|
||||
SetCurrentValue(IsDropDownOpenProperty, ValueBoxes.TrueBox);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public interface ISplitButtonItem
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class SplitButtonItem : MenuItem, ISplitButtonItem
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -147,7 +147,6 @@ namespace HandyControl.Controls
|
||||
dp._calendarWithClock.Focus();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\RectangleAttach.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\TextBlockAttach.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Block\FloatingBlock.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Button\SplitButton\ISplitButtonItem.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Button\SplitButton\SplitButton.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Button\SplitButton\SplitButtonItem.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Button\SplitButton.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Growl\GrowlWindow.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Image\ImageBlock.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Magnifier.cs" />
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
<ResourceDictionary Source="../ToggleButton.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<Style BasedOn="{StaticResource MenuItemBaseStyle}" TargetType="controls:SplitButtonItem"/>
|
||||
|
||||
<Style x:Key="SplitButtonBaseStyle" BasedOn="{StaticResource BaseStyle}" TargetType="controls:SplitButton">
|
||||
<Setter Property="Height" Value="{StaticResource DefaultControlHeight}"/>
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
|
||||
@@ -36,10 +34,10 @@
|
||||
<Path x:Name="PathMain" Width="{TemplateBinding controls:IconElement.Width}" Height="{TemplateBinding controls:IconElement.Height}" Fill="{TemplateBinding Foreground}" SnapsToDevicePixels="True" Stretch="Uniform" Data="{TemplateBinding controls:IconElement.Geometry}"/>
|
||||
<ContentPresenter x:Name="ContentPresenterMain" RecognizesAccessKey="True" VerticalAlignment="Center" Margin="6,0,0,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
|
||||
</StackPanel>
|
||||
<ToggleButton x:Name="PART_Arrow" Foreground="{TemplateBinding Foreground}" IsChecked="{TemplateBinding IsDropDownOpen}" Width="22" Height="Auto" Padding="0,10,8,10" HorizontalContentAlignment="Left" Grid.Column="1" Style="{StaticResource ToggleButtonIconTransparent}" controls:IconSwitchElement.GeometrySelected="{StaticResource UpGeometry}" controls:IconElement.Geometry="{StaticResource DownGeometry}"/>
|
||||
<ToggleButton x:Name="PART_Arrow" Foreground="{TemplateBinding Foreground}" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Width="22" Height="Auto" Padding="0,10,8,10" HorizontalContentAlignment="Left" Grid.Column="1" Style="{StaticResource ToggleButtonIconTransparent}" controls:IconSwitchElement.GeometrySelected="{StaticResource UpGeometry}" controls:IconElement.Geometry="{StaticResource DownGeometry}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
<Popup x:Name="PART_Popup" AllowsTransparency="true" IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{StaticResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
|
||||
<Popup AllowsTransparency="true" StaysOpen="False" IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="Fade" Placement="Bottom">
|
||||
<Border CornerRadius="{Binding Path=(controls:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" x:Name="dropDownBorder" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1" Background="{DynamicResource RegionBrush}">
|
||||
<ScrollViewer Margin="0,4" x:Name="DropDownScrollViewer">
|
||||
<controls:SimplePanel RenderOptions.ClearTypeHint="Enabled">
|
||||
@@ -60,13 +58,6 @@
|
||||
<Setter Property="Visibility" Value="Collapsed" TargetName="PathMain"/>
|
||||
<Setter Property="Margin" Value="0" TargetName="ContentPresenterMain"/>
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="HitMode" Value="Hover"/>
|
||||
<Condition Property="IsMouseOver" Value="True"/>
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="IsDropDownOpen" Value="True"/>
|
||||
</MultiTrigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="HitMode" Value="Click"/>
|
||||
|
||||
Reference in new issue
Block a user