feat: upgrade version. implement more keys.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<Nullable>enable</Nullable>
|
||||
<AvaloniaVersion>11.0.9</AvaloniaVersion>
|
||||
<AvaloniaVersion>11.0.10</AvaloniaVersion>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
||||
@@ -1,15 +1,36 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Ursa.Demo.Pages.NumPadDemo">
|
||||
<UserControl
|
||||
x:Class="Ursa.Demo.Pages.NumPadDemo"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
mc:Ignorable="d">
|
||||
<StackPanel HorizontalAlignment="Left">
|
||||
<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>
|
||||
<TextBox
|
||||
HorizontalAlignment="Stretch"
|
||||
u:NumPad.Attach="True"
|
||||
Watermark="Invoke NumPad" />
|
||||
<TextBox
|
||||
HorizontalAlignment="Stretch"
|
||||
u:NumPad.Attach="True"
|
||||
Watermark="Invoke NumPad" />
|
||||
<TextBox
|
||||
HorizontalAlignment="Stretch"
|
||||
u:NumPad.Attach="True"
|
||||
Watermark="Invoke NumPad" />
|
||||
<u:IPv4Box Width="200" u:NumPad.Attach="True" />
|
||||
<u:NumericIntUpDown
|
||||
HorizontalAlignment="Stretch"
|
||||
u:NumPad.Attach="True"
|
||||
Watermark="Invoke NumPad" />
|
||||
<Border Theme="{DynamicResource CardBorder}">
|
||||
<StackPanel>
|
||||
<TextBox Name="text" Width="200" />
|
||||
<u:NumPad Target="{Binding #text}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
||||
@@ -3,34 +3,37 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="https://irihi.tech/ursa">
|
||||
<!-- Add Resources Here -->
|
||||
<Design.PreviewWith>
|
||||
<u:NumPad></u:NumPad>
|
||||
</Design.PreviewWith>
|
||||
<ControlTheme x:Key="{x:Type u:NumPad}" TargetType="{x:Type u:NumPad}">
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="u:NumPad">
|
||||
<Border>
|
||||
<Border.Styles>
|
||||
<Style Selector="RepeatButton">
|
||||
<Setter Property="Command" Value="{Binding $parent[u:NumPad].ProcessClick}" />
|
||||
<Setter Property="CommandParameter" Value="{Binding $self.Content}" />
|
||||
<Setter Property="Width" Value="48" />
|
||||
<Setter Property="Height" Value="48" />
|
||||
</Style>
|
||||
<Style Selector="u|NumPadButton">
|
||||
<Setter Property="NumMode" Value="{Binding $parent[u:NumPad].NumMode}" />
|
||||
<Setter Property="Command" Value="{Binding $parent[u:NumPad].ProcessClick}" />
|
||||
<Setter Property="Focusable" Value="False"></Setter>
|
||||
<Setter Property="Focusable" Value="False" />
|
||||
<Setter Property="CommandParameter" Value="{Binding $self}" />
|
||||
<Setter Property="Width" Value="54" />
|
||||
<Setter Property="Height" Value="54" />
|
||||
<Setter Property="UseLayoutRounding" Value="False"></Setter>
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
|
||||
<Setter Property="VerticalAlignment" Value="Stretch"></Setter>
|
||||
<Setter Property="Margin" Value="1" />
|
||||
</Style>
|
||||
</Border.Styles>
|
||||
<Grid ColumnDefinitions="*,*,*,*" RowDefinitions="*,*,*,*,*">
|
||||
<Grid ColumnDefinitions="*,*,*,*" RowDefinitions="*,*,*,*,*" HorizontalAlignment="Left" VerticalAlignment="Top">
|
||||
<ToggleButton
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Width="54"
|
||||
Focusable="False"
|
||||
Height="54"
|
||||
MinWidth="54"
|
||||
MinHeight="54"
|
||||
Padding="0"
|
||||
Focusable="False"
|
||||
FontWeight="Regular"
|
||||
Margin="1"
|
||||
IsChecked="{TemplateBinding NumMode,
|
||||
Mode=TwoWay}">
|
||||
<TextBlock>
|
||||
@@ -44,14 +47,122 @@
|
||||
Grid.Column="1"
|
||||
FunctionContent="/"
|
||||
NumContent="/"
|
||||
NumKey="OemQuestion" />
|
||||
NumKey="Divide" />
|
||||
<u:NumPadButton
|
||||
Grid.Row="0"
|
||||
Grid.Column="2"
|
||||
FunctionContent="*"
|
||||
NumContent="*"
|
||||
NumKey="Multiply" />
|
||||
<u:NumPadButton
|
||||
Grid.Row="0"
|
||||
Grid.Column="3"
|
||||
FunctionContent="-"
|
||||
NumContent="-"
|
||||
NumKey="Subtract" />
|
||||
<u:NumPadButton
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
Grid.Column="0"
|
||||
FunctionContent="Home"
|
||||
FunctionKey="Home"
|
||||
NumContent="7"
|
||||
NumKey="NumPad7" />
|
||||
<u:NumPadButton
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
FunctionContent="Up"
|
||||
FunctionKey="Up"
|
||||
NumContent="8"
|
||||
NumKey="NumPad8" />
|
||||
<u:NumPadButton
|
||||
Grid.Row="1"
|
||||
Grid.Column="2"
|
||||
FunctionKey="PageUp"
|
||||
NumContent="9"
|
||||
NumKey="NumPad9">
|
||||
<u:NumPadButton.FunctionContent>
|
||||
<TextBlock><Run Text="Page"/><LineBreak/><Run Text="Up"/></TextBlock>
|
||||
</u:NumPadButton.FunctionContent>
|
||||
</u:NumPadButton>
|
||||
<u:NumPadButton
|
||||
Grid.Row="1"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="3"
|
||||
Height="{x:Static x:Double.NaN}"
|
||||
VerticalAlignment="Stretch"
|
||||
FunctionContent="+"
|
||||
NumContent="+"
|
||||
NumKey="Add" />
|
||||
<u:NumPadButton
|
||||
Grid.Row="2"
|
||||
Grid.Column="0"
|
||||
FunctionContent="Left"
|
||||
FunctionKey="Left"
|
||||
NumContent="4"
|
||||
NumKey="NumPad4" />
|
||||
<u:NumPadButton
|
||||
Grid.Row="2"
|
||||
Grid.Column="1"
|
||||
FunctionContent=" "
|
||||
FunctionKey="None"
|
||||
NumContent="5"
|
||||
NumKey="NumPad5" />
|
||||
<u:NumPadButton
|
||||
Grid.Row="2"
|
||||
Grid.Column="2"
|
||||
FunctionContent="Right"
|
||||
FunctionKey="Right"
|
||||
NumContent="6"
|
||||
NumKey="NumPad6" />
|
||||
<u:NumPadButton
|
||||
Grid.Row="3"
|
||||
Grid.Column="0"
|
||||
FunctionContent="End"
|
||||
FunctionKey="End"
|
||||
NumContent="1"
|
||||
NumKey="NumPad1" />
|
||||
<u:NumPadButton
|
||||
Grid.Row="3"
|
||||
Grid.Column="1"
|
||||
FunctionContent="Down"
|
||||
FunctionKey="Down"
|
||||
NumContent="2"
|
||||
NumKey="NumPad2" />
|
||||
<u:NumPadButton
|
||||
Grid.Row="3"
|
||||
Grid.Column="2"
|
||||
FunctionKey="PageDown"
|
||||
NumContent="3"
|
||||
NumKey="NumPad3">
|
||||
<u:NumPadButton.FunctionContent>
|
||||
<TextBlock><Run Text="Page"/><LineBreak/><Run Text="Down"/></TextBlock>
|
||||
</u:NumPadButton.FunctionContent>
|
||||
</u:NumPadButton>
|
||||
<u:NumPadButton
|
||||
Grid.Row="3"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="3"
|
||||
Height="{x:Static x:Double.NaN}"
|
||||
VerticalAlignment="Stretch"
|
||||
FunctionContent="Enter"
|
||||
FunctionKey="Enter"
|
||||
NumContent="Enter" />
|
||||
<u:NumPadButton
|
||||
Grid.Row="4"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
FunctionContent="Insert"
|
||||
FunctionKey="Insert"
|
||||
NumContent="0"
|
||||
Width="{x:Static x:Double.NaN}"
|
||||
NumKey="NumPad0" />
|
||||
<u:NumPadButton
|
||||
Grid.Row="4"
|
||||
Grid.Column="2"
|
||||
FunctionContent="Delete"
|
||||
FunctionKey="Delete"
|
||||
NumContent="."
|
||||
NumKey="Decimal"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
@@ -62,10 +173,13 @@
|
||||
<Setter Property="Focusable" Value="False" />
|
||||
<Setter Property="Cursor" Value="Hand" />
|
||||
<Setter Property="Background" Value="{DynamicResource ButtonDefaultBackground}" />
|
||||
<Setter Property="CornerRadius" Value="3"/>
|
||||
<Setter Property="CornerRadius" Value="3" />
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="u:NumPadButton">
|
||||
<Border Name="PART_Background" Background="{TemplateBinding Background}" CornerRadius="{TemplateBinding CornerRadius}">
|
||||
<Border
|
||||
Name="PART_Background"
|
||||
Background="{TemplateBinding Background}"
|
||||
CornerRadius="{TemplateBinding CornerRadius}">
|
||||
<Panel>
|
||||
<ContentPresenter
|
||||
Name="PART_ContentPresenter"
|
||||
@@ -84,10 +198,10 @@
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
<Style Selector="^:pointerover /template/ Border#PART_Background">
|
||||
<Setter Property="Background" Value="{DynamicResource ButtonDefaultPointeroverBackground}"></Setter>
|
||||
<Setter Property="Background" Value="{DynamicResource ButtonDefaultPointeroverBackground}" />
|
||||
</Style>
|
||||
<Style Selector="^:pressed /template/ Border#PART_Background">
|
||||
<Setter Property="Background" Value="{DynamicResource ButtonDefaultPressedBackground}"></Setter>
|
||||
<Setter Property="Background" Value="{DynamicResource ButtonDefaultPressedBackground}" />
|
||||
</Style>
|
||||
</ControlTheme>
|
||||
</ResourceDictionary>
|
||||
|
||||
@@ -76,14 +76,30 @@ public class NumPad: TemplatedControl
|
||||
[Key.NumPad7] = "7",
|
||||
[Key.NumPad8] = "8",
|
||||
[Key.NumPad9] = "9",
|
||||
[Key.OemPlus] = "+",
|
||||
[Key.OemMinus] = "-",
|
||||
[Key.Add] = "+",
|
||||
[Key.Subtract] = "-",
|
||||
[Key.Multiply] = "*",
|
||||
[Key.Divide] = "/",
|
||||
[Key.Decimal] = ".",
|
||||
};
|
||||
|
||||
public void ProcessClick(object o)
|
||||
{
|
||||
if (Target?.IsFocused != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (o is NumPadButton b)
|
||||
{
|
||||
if (b.NumKey is null)
|
||||
{
|
||||
Target?.RaiseEvent(new KeyEventArgs()
|
||||
{
|
||||
Source = this,
|
||||
RoutedEvent = KeyDownEvent,
|
||||
Key = b.FunctionKey ?? Key.None,
|
||||
});
|
||||
}
|
||||
if (b is { NumMode: true, NumKey: not null })
|
||||
{
|
||||
Target?.RaiseEvent(new TextInputEventArgs()
|
||||
|
||||
Reference in New Issue
Block a user