feat: template binding
This commit is contained in:
@@ -6,7 +6,16 @@
|
||||
mc:Ignorable="d" d:DesignWidth="800"
|
||||
d:DesignHeight="450"
|
||||
x:Class="Ursa.Demo.Pages.RangeSliderDemo">
|
||||
<UserControl.Styles>
|
||||
<Style Selector="u|NumericDoubleUpDown">
|
||||
<Setter Property="Width" Value="300"></Setter>
|
||||
</Style>
|
||||
</UserControl.Styles>
|
||||
<StackPanel>
|
||||
<u:RangeSlider Height="60"/>
|
||||
<u:RangeSlider Name="range" Height="60"/>
|
||||
<u:NumericDoubleUpDown InnerLeftContent="Minimum" Value="{Binding #range.Minimum, Mode=TwoWay}" />
|
||||
<u:NumericDoubleUpDown InnerLeftContent="Maximum" Value="{Binding #range.Maximum, Mode=TwoWay}" />
|
||||
<u:NumericDoubleUpDown InnerLeftContent="LowerValue" Value="{Binding #range.LowerValue, Mode=TwoWay}" />
|
||||
<u:NumericDoubleUpDown InnerLeftContent="UpperValue" Value="{Binding #range.UpperValue, Mode=TwoWay}" />
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
<ControlTheme x:Key="{x:Type u:RangeSlider}" TargetType="u:RangeSlider">
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="u:RangeSlider">
|
||||
<u:RangeTrack Minimum="0" Maximum="100" LowerValue="20" UpperValue="65">
|
||||
<u:RangeTrack
|
||||
Minimum="{Binding Minimum, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
|
||||
Maximum="{Binding Maximum, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
|
||||
LowerValue="{Binding LowerValue, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
|
||||
UpperValue="{Binding UpperValue, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay} ">
|
||||
<u:RangeTrack.LowerButton>
|
||||
<Button Content="Lower"></Button>
|
||||
</u:RangeTrack.LowerButton>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Primitives;
|
||||
@@ -12,4 +13,41 @@ public class RangeSlider: TemplatedControl
|
||||
public const string PART_DecreaseButton = "PART_DecreaseButton";
|
||||
public const string PART_IncreaseButton = "PART_IncreaseButton";
|
||||
public const string PART_Track = "PART_Track";
|
||||
|
||||
public static readonly StyledProperty<double> MinimumProperty = RangeTrack.MinimumProperty.AddOwner<RangeSlider>();
|
||||
public double Minimum
|
||||
{
|
||||
get => GetValue(MinimumProperty);
|
||||
set => SetValue(MinimumProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<double> MaximumProperty = RangeTrack.MaximumProperty.AddOwner<RangeSlider>();
|
||||
public double Maximum
|
||||
{
|
||||
get => GetValue(MaximumProperty);
|
||||
set => SetValue(MaximumProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<double> LowerValueProperty = RangeTrack.LowerValueProperty.AddOwner<RangeSlider>();
|
||||
public double LowerValue
|
||||
{
|
||||
get => GetValue(LowerValueProperty);
|
||||
set => SetValue(LowerValueProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<double> UpperValueProperty = RangeTrack.UpperValueProperty.AddOwner<RangeSlider>();
|
||||
public double UpperValue
|
||||
{
|
||||
get => GetValue(UpperValueProperty);
|
||||
set => SetValue(UpperValueProperty, value);
|
||||
}
|
||||
|
||||
static RangeSlider()
|
||||
{
|
||||
MinimumProperty.OverrideDefaultValue<RangeSlider>(0);
|
||||
MaximumProperty.OverrideDefaultValue<RangeSlider>(100);
|
||||
LowerValueProperty.OverrideDefaultValue<RangeSlider>(0);
|
||||
UpperValueProperty.OverrideDefaultValue<RangeSlider>(100);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Layout;
|
||||
@@ -23,7 +24,7 @@ public class RangeTrack: Control
|
||||
private Vector _lastDrag;
|
||||
|
||||
public static readonly StyledProperty<double> MinimumProperty = AvaloniaProperty.Register<RangeTrack, double>(
|
||||
nameof(Minimum), coerce: CoerceMinimum);
|
||||
nameof(Minimum), coerce: CoerceMinimum, defaultBindingMode:BindingMode.TwoWay);
|
||||
|
||||
public double Minimum
|
||||
{
|
||||
@@ -32,7 +33,7 @@ public class RangeTrack: Control
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<double> MaximumProperty = AvaloniaProperty.Register<RangeTrack, double>(
|
||||
nameof(Maximum), coerce: CoerceMaximum);
|
||||
nameof(Maximum), coerce: CoerceMaximum, defaultBindingMode: BindingMode.TwoWay);
|
||||
|
||||
public double Maximum
|
||||
{
|
||||
@@ -41,7 +42,7 @@ public class RangeTrack: Control
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<double> LowerValueProperty = AvaloniaProperty.Register<RangeTrack, double>(
|
||||
nameof(LowerValue), coerce: CoerceLowerValue);
|
||||
nameof(LowerValue), coerce: CoerceLowerValue, defaultBindingMode: BindingMode.TwoWay);
|
||||
|
||||
public double LowerValue
|
||||
{
|
||||
@@ -50,7 +51,7 @@ public class RangeTrack: Control
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<double> UpperValueProperty = AvaloniaProperty.Register<RangeTrack, double>(
|
||||
nameof(UpperValue), coerce: CoerceUpperValue);
|
||||
nameof(UpperValue), coerce: CoerceUpperValue, defaultBindingMode: BindingMode.TwoWay);
|
||||
|
||||
public double UpperValue
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user