feat: implement more buttons.
This commit is contained in:
@@ -50,6 +50,7 @@
|
|||||||
<TextBox u:NumPad.Attach="True" Width="100" Watermark="Invoke NumPad"></TextBox>
|
<TextBox u:NumPad.Attach="True" Width="100" Watermark="Invoke NumPad"></TextBox>
|
||||||
<TextBox u:NumPad.Attach="True" Width="100" Watermark="Invoke NumPad"></TextBox>
|
<TextBox u:NumPad.Attach="True" Width="100" Watermark="Invoke NumPad"></TextBox>
|
||||||
<TextBox u:NumPad.Attach="True" Width="100" Watermark="Invoke NumPad"></TextBox>
|
<TextBox u:NumPad.Attach="True" Width="100" Watermark="Invoke NumPad"></TextBox>
|
||||||
|
<u:IPv4Box u:NumPad.Attach="True" Width="200" ></u:IPv4Box>
|
||||||
<u:NumericIntUpDown u:NumPad.Attach="True" Width="100" Watermark="Invoke NumPad"></u:NumericIntUpDown>
|
<u:NumericIntUpDown u:NumPad.Attach="True" Width="100" Watermark="Invoke NumPad"></u:NumericIntUpDown>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -1,12 +1,77 @@
|
|||||||
<ResourceDictionary xmlns="https://github.com/avaloniaui"
|
<ResourceDictionary
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:u="https://irihi.tech/ursa">
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
<!-- Add Resources Here -->
|
xmlns:u="https://irihi.tech/ursa">
|
||||||
|
<!-- Add Resources Here -->
|
||||||
<ControlTheme x:Key="{x:Type u:NumPad}" TargetType="{x:Type u:NumPad}">
|
<ControlTheme x:Key="{x:Type u:NumPad}" TargetType="{x:Type u:NumPad}">
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<ControlTemplate TargetType="u:NumPad">
|
<ControlTemplate TargetType="u:NumPad">
|
||||||
<Border Padding="48">
|
<Border Padding="48">
|
||||||
<Button Focusable="False" Name="{x:Static u:NumPad.PART_Seven}" Content="7" Width="32"></Button>
|
<Border.Styles>
|
||||||
|
<Style Selector="Button">
|
||||||
|
<Setter Property="Command" Value="{Binding $parent[u:NumPad].InputNumber}" />
|
||||||
|
<Setter Property="CommandParameter" Value="{Binding $self.Content}" />
|
||||||
|
</Style>
|
||||||
|
</Border.Styles>
|
||||||
|
<Grid ColumnDefinitions="*,*,*" RowDefinitions="*,*,*,*">
|
||||||
|
<Button
|
||||||
|
Grid.Row="0"
|
||||||
|
Grid.Column="0"
|
||||||
|
Content="7"
|
||||||
|
Focusable="False" />
|
||||||
|
<Button
|
||||||
|
Grid.Row="0"
|
||||||
|
Grid.Column="1"
|
||||||
|
Content="8"
|
||||||
|
Focusable="False" />
|
||||||
|
<Button
|
||||||
|
Grid.Row="0"
|
||||||
|
Grid.Column="2"
|
||||||
|
Content="9"
|
||||||
|
Focusable="False" />
|
||||||
|
<Button
|
||||||
|
Grid.Row="1"
|
||||||
|
Grid.Column="0"
|
||||||
|
Content="4"
|
||||||
|
Focusable="False" />
|
||||||
|
<Button
|
||||||
|
Grid.Row="1"
|
||||||
|
Grid.Column="1"
|
||||||
|
Content="5"
|
||||||
|
Focusable="False" />
|
||||||
|
<Button
|
||||||
|
Grid.Row="1"
|
||||||
|
Grid.Column="2"
|
||||||
|
Content="6"
|
||||||
|
Focusable="False" />
|
||||||
|
<Button
|
||||||
|
Grid.Row="2"
|
||||||
|
Grid.Column="0"
|
||||||
|
Content="1"
|
||||||
|
Focusable="False" />
|
||||||
|
<Button
|
||||||
|
Grid.Row="2"
|
||||||
|
Grid.Column="1"
|
||||||
|
Content="2"
|
||||||
|
Focusable="False" />
|
||||||
|
<Button
|
||||||
|
Grid.Row="2"
|
||||||
|
Grid.Column="2"
|
||||||
|
Content="3"
|
||||||
|
Focusable="False" />
|
||||||
|
<Button
|
||||||
|
Grid.Row="3"
|
||||||
|
Grid.ColumnSpan="2"
|
||||||
|
Grid.Column="0"
|
||||||
|
Content="0"
|
||||||
|
Focusable="False" />
|
||||||
|
<Button
|
||||||
|
Grid.Row="3"
|
||||||
|
Grid.Column="2"
|
||||||
|
Content="."
|
||||||
|
Focusable="False" />
|
||||||
|
</Grid>
|
||||||
|
|
||||||
</Border>
|
</Border>
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
</Setter>
|
</Setter>
|
||||||
|
|||||||
@@ -8,10 +8,8 @@ using Irihi.Avalonia.Shared.Helpers;
|
|||||||
|
|
||||||
namespace Ursa.Controls;
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
[TemplatePart(NumPad.PART_Seven, typeof(Button))]
|
|
||||||
public class NumPad: TemplatedControl
|
public class NumPad: TemplatedControl
|
||||||
{
|
{
|
||||||
public const string PART_Seven = "PART_Seven";
|
|
||||||
private Button? _sevenButton;
|
private Button? _sevenButton;
|
||||||
public static readonly StyledProperty<InputElement?> TargetProperty = AvaloniaProperty.Register<NumPad, InputElement?>(
|
public static readonly StyledProperty<InputElement?> TargetProperty = AvaloniaProperty.Register<NumPad, InputElement?>(
|
||||||
nameof(Target));
|
nameof(Target));
|
||||||
@@ -68,9 +66,6 @@ public class NumPad: TemplatedControl
|
|||||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnApplyTemplate(e);
|
base.OnApplyTemplate(e);
|
||||||
Button.ClickEvent.RemoveHandler(OnSevenButtonClick, _sevenButton);
|
|
||||||
_sevenButton = e.NameScope.Find<Button>(PART_Seven);
|
|
||||||
Button.ClickEvent.AddHandler(OnSevenButtonClick, _sevenButton);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSevenButtonClick(object sender, RoutedEventArgs e)
|
private void OnSevenButtonClick(object sender, RoutedEventArgs e)
|
||||||
@@ -82,4 +77,14 @@ public class NumPad: TemplatedControl
|
|||||||
Text = "7",
|
Text = "7",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void InputNumber(object o)
|
||||||
|
{
|
||||||
|
Target?.RaiseEvent(new TextInputEventArgs()
|
||||||
|
{
|
||||||
|
Source = this,
|
||||||
|
RoutedEvent = TextInputEvent,
|
||||||
|
Text = o.ToString(),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -213,7 +213,6 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl
|
|||||||
_textBox?.Focus();
|
_textBox?.Focus();
|
||||||
_textBox!.IsReadOnly = true;
|
_textBox!.IsReadOnly = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnTextInput(TextInputEventArgs e)
|
protected override void OnTextInput(TextInputEventArgs e)
|
||||||
|
|||||||
Reference in New Issue
Block a user