close #234
now you can customize dot by PageButtonStyle property @jingsong-liu
This commit is contained in:
1 parent
d0dc957c81
commit
453839e763
4 files changed
+78
-41
No files matched your search
@@ -173,9 +173,16 @@ namespace HandyControl.Controls
|
|||||||
storyboard.Completed += (s, e) =>
|
storyboard.Completed += (s, e) =>
|
||||||
{
|
{
|
||||||
var layer = AdornerLayer.GetAdornerLayer(element);
|
var layer = AdornerLayer.GetAdornerLayer(element);
|
||||||
if (layer == null) return;
|
if (layer != null)
|
||||||
|
{
|
||||||
|
layer.Remove(adorner);
|
||||||
|
}
|
||||||
|
else if (adorner.Parent is AdornerLayer parent)
|
||||||
|
{
|
||||||
|
parent.Remove(adorner);
|
||||||
|
}
|
||||||
|
|
||||||
adorner.Child = null;
|
adorner.Child = null;
|
||||||
layer.Remove(adorner);
|
|
||||||
};
|
};
|
||||||
storyboard.Children.Add(animationX);
|
storyboard.Children.Add(animationX);
|
||||||
storyboard.Children.Add(animationY);
|
storyboard.Children.Add(animationY);
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ using System.Windows.Controls;
|
|||||||
using System.Windows.Controls.Primitives;
|
using System.Windows.Controls.Primitives;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Markup;
|
using System.Windows.Markup;
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
using HandyControl.Data;
|
using HandyControl.Data;
|
||||||
using HandyControl.Interactivity;
|
using HandyControl.Interactivity;
|
||||||
@@ -42,7 +41,7 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
private int _pageIndex = -1;
|
private int _pageIndex = -1;
|
||||||
|
|
||||||
private Button _selectedButton;
|
private RadioButton _selectedButton;
|
||||||
|
|
||||||
private DispatcherTimer _updateTimer;
|
private DispatcherTimer _updateTimer;
|
||||||
|
|
||||||
@@ -104,6 +103,15 @@ namespace HandyControl.Controls
|
|||||||
set => SetValue(IsCenterProperty, value);
|
set => SetValue(IsCenterProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static readonly DependencyProperty PageButtonStyleProperty = DependencyProperty.Register(
|
||||||
|
"PageButtonStyle", typeof(Style), typeof(Carousel), new PropertyMetadata(default(Style)));
|
||||||
|
|
||||||
|
public Style PageButtonStyle
|
||||||
|
{
|
||||||
|
get => (Style) GetValue(PageButtonStyleProperty);
|
||||||
|
set => SetValue(PageButtonStyleProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
public Carousel()
|
public Carousel()
|
||||||
{
|
{
|
||||||
CommandBindings.Add(new CommandBinding(ControlCommands.Prev, ButtonPrev_OnClick));
|
CommandBindings.Add(new CommandBinding(ControlCommands.Prev, ButtonPrev_OnClick));
|
||||||
@@ -210,15 +218,21 @@ namespace HandyControl.Controls
|
|||||||
_panelPage.Children.Clear();
|
_panelPage.Children.Clear();
|
||||||
for (var i = 0; i < count; i++)
|
for (var i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
_panelPage.Children.Add(CreatePateButton());
|
_panelPage.Children.Add(new RadioButton
|
||||||
|
{
|
||||||
|
Style = PageButtonStyle
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index == -1 && count > 0) index = 0;
|
if (index == -1 && count > 0) index = 0;
|
||||||
if (index >= 0 && index < count)
|
if (index >= 0 && index < count)
|
||||||
{
|
{
|
||||||
var button = _panelPage.Children[index];
|
if (_panelPage.Children[index] is RadioButton button)
|
||||||
button.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent, button));
|
{
|
||||||
UpdateItemsPosition();
|
button.IsChecked = true;
|
||||||
|
button.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent, button));
|
||||||
|
UpdateItemsPosition();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,40 +265,17 @@ namespace HandyControl.Controls
|
|||||||
UpdateItemsPosition();
|
UpdateItemsPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 创建页按钮
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
private Button CreatePateButton()
|
|
||||||
{
|
|
||||||
var button = new Button
|
|
||||||
{
|
|
||||||
Style = ResourceHelper.GetResource<Style>(ResourceToken.ButtonCustom),
|
|
||||||
Content = new Border
|
|
||||||
{
|
|
||||||
Width = 10,
|
|
||||||
Height = 10,
|
|
||||||
CornerRadius = new CornerRadius(5),
|
|
||||||
Background = Brushes.White,
|
|
||||||
Margin = new Thickness(5, 0, 5, 0),
|
|
||||||
BorderThickness = new Thickness(1),
|
|
||||||
BorderBrush = ResourceHelper.GetResource<Brush>(ResourceToken.PrimaryBrush)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonPages_OnClick(object sender, RoutedEventArgs e)
|
private void ButtonPages_OnClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (!CheckNull()) return;
|
if (!CheckNull()) return;
|
||||||
if (_selectedButton != null && _selectedButton.Content is Border borderOri)
|
|
||||||
borderOri.Background = Brushes.White;
|
_selectedButton = e.OriginalSource as RadioButton;
|
||||||
_selectedButton = e.OriginalSource as Button;
|
|
||||||
if (_selectedButton != null && _selectedButton.Content is Border border)
|
|
||||||
border.Background = ResourceHelper.GetResource<Brush>(ResourceToken.PrimaryBrush);
|
|
||||||
var index = _panelPage.Children.IndexOf(_selectedButton);
|
var index = _panelPage.Children.IndexOf(_selectedButton);
|
||||||
if (index != -1)
|
if (index != -1)
|
||||||
|
{
|
||||||
PageIndex = index;
|
PageIndex = index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonPrev_OnClick(object sender, RoutedEventArgs e) => PageIndex--;
|
private void ButtonPrev_OnClick(object sender, RoutedEventArgs e) => PageIndex--;
|
||||||
|
|||||||
@@ -153,10 +153,20 @@ namespace HandyControl.Controls
|
|||||||
base.OnMouseLeave(e);
|
base.OnMouseLeave(e);
|
||||||
|
|
||||||
var layer = AdornerLayer.GetAdornerLayer(this);
|
var layer = AdornerLayer.GetAdornerLayer(this);
|
||||||
if (layer == null) return;
|
if (layer != null)
|
||||||
layer.Remove(_adorner);
|
{
|
||||||
_adorner.Child = null;
|
layer.Remove(_adorner);
|
||||||
_adorner = null;
|
}
|
||||||
|
else if (_adorner != null && _adorner.Parent is AdornerLayer parent)
|
||||||
|
{
|
||||||
|
parent.Remove(_adorner);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_adorner != null)
|
||||||
|
{
|
||||||
|
_adorner.Child = null;
|
||||||
|
_adorner = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnApplyTemplate()
|
public override void OnApplyTemplate()
|
||||||
|
|||||||
@@ -24,7 +24,36 @@
|
|||||||
<Setter Property="ItemContainerStyle" Value="{StaticResource CarouselListBoxItemStyle}"/>
|
<Setter Property="ItemContainerStyle" Value="{StaticResource CarouselListBoxItemStyle}"/>
|
||||||
</Style>
|
</Style>
|
||||||
|
|
||||||
|
<Style x:Key="CarouselPateButton" BasedOn="{StaticResource BaseStyle}" TargetType="RadioButton">
|
||||||
|
<Setter Property="Margin" Value="5,0"/>
|
||||||
|
<Setter Property="Width" Value="10"/>
|
||||||
|
<Setter Property="Height" Value="10"/>
|
||||||
|
<Setter Property="Background" Value="White"/>
|
||||||
|
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryBrush}"/>
|
||||||
|
<Setter Property="Padding" Value="0"/>
|
||||||
|
<Setter Property="BorderThickness" Value="1"/>
|
||||||
|
<Setter Property="Template">
|
||||||
|
<Setter.Value>
|
||||||
|
<ControlTemplate TargetType="ToggleButton">
|
||||||
|
<Border CornerRadius="5" SnapsToDevicePixels="true" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}"/>
|
||||||
|
<ControlTemplate.Triggers>
|
||||||
|
<Trigger Property="IsMouseOver" Value="True">
|
||||||
|
<Setter Property="Opacity" Value=".9"/>
|
||||||
|
</Trigger>
|
||||||
|
<Trigger Property="IsPressed" Value="True">
|
||||||
|
<Setter Property="Opacity" Value=".6"/>
|
||||||
|
</Trigger>
|
||||||
|
<Trigger Property="IsChecked" Value="True">
|
||||||
|
<Setter Property="Background" Value="{DynamicResource PrimaryBrush}"/>
|
||||||
|
</Trigger>
|
||||||
|
</ControlTemplate.Triggers>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
|
</Style>
|
||||||
|
|
||||||
<Style TargetType="controls:Carousel" BasedOn="{StaticResource CarouselListBox}">
|
<Style TargetType="controls:Carousel" BasedOn="{StaticResource CarouselListBox}">
|
||||||
|
<Setter Property="PageButtonStyle" Value="{StaticResource CarouselPateButton}"/>
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate TargetType="controls:Carousel">
|
<ControlTemplate TargetType="controls:Carousel">
|
||||||
@@ -46,7 +75,7 @@
|
|||||||
</ControlTemplate.Triggers>
|
</ControlTemplate.Triggers>
|
||||||
<controls:SimplePanel ClipToBounds="True">
|
<controls:SimplePanel ClipToBounds="True">
|
||||||
<ItemsPresenter x:Name="PART_ItemsControl" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="Left"/>
|
<ItemsPresenter x:Name="PART_ItemsControl" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="Left"/>
|
||||||
<controls:SimplePanel Name="GridTop" Opacity="0">
|
<controls:SimplePanel x:Name="GridTop" Opacity="0">
|
||||||
<Button Command="interactivity:ControlCommands.Prev" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="30,0,0,0" Style="{StaticResource ButtonCustom}">
|
<Button Command="interactivity:ControlCommands.Prev" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="30,0,0,0" Style="{StaticResource ButtonCustom}">
|
||||||
<Border Width="50" Height="100" Background="{DynamicResource DarkOpacityBrush}" CornerRadius="4">
|
<Border Width="50" Height="100" Background="{DynamicResource DarkOpacityBrush}" CornerRadius="4">
|
||||||
<Path Margin="16" Fill="White" Style="{StaticResource LeftPathStyle}"/>
|
<Path Margin="16" Fill="White" Style="{StaticResource LeftPathStyle}"/>
|
||||||
|
|||||||
Reference in new issue
Block a user