committed by
GitHub
13 changed files with 279 additions and 22 deletions
@ -0,0 +1,42 @@ |
|||
<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" |
|||
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="250" |
|||
x:Class="ControlCatalog.Pages.LabelsPage" |
|||
x:Name="_labelsPage"> |
|||
<UserControl.Styles> |
|||
<Style Selector="Label"> |
|||
<Setter Property="VerticalAlignment" Value="Center"/> |
|||
<Setter Property="Margin" Value="6,3,0,3"/> |
|||
</Style> |
|||
<Style Selector="TextBox"> |
|||
<Setter Property="VerticalAlignment" Value="Center"/> |
|||
<Setter Property="Margin" Value="0,3,6,3"/> |
|||
</Style> |
|||
<Style Selector="CheckBox"> |
|||
<Setter Property="VerticalAlignment" Value="Center"/> |
|||
<Setter Property="Margin" Value="0,3,6,3"/> |
|||
</Style> |
|||
<Style Selector="Button[IsDefault=true]"> |
|||
<Setter Property="Background" Value="{DynamicResource HighlightBrush}"/> |
|||
</Style> |
|||
</UserControl.Styles> |
|||
<ScrollViewer VerticalScrollBarVisibility="Auto" |
|||
HorizontalScrollBarVisibility="Hidden"> |
|||
<Grid HorizontalAlignment="Left" VerticalAlignment="Top" RowDefinitions="Auto,Auto,Auto,Auto,Auto,*" ColumnDefinitions="Auto,6,*" Width="246"> |
|||
<Label Target="{Binding #firstNameEdit}" Grid.Row="0" Grid.Column="0">_First name</Label> |
|||
<TextBox Name="firstNameEdit" Grid.Column="2" Grid.Row="0" Text="{Binding FirstName}"></TextBox> |
|||
<Label Target="{Binding #lastNameEdit}" Grid.Row="1" Grid.Column="0">_Last name</Label> |
|||
<TextBox Name="lastNameEdit" Grid.Column="2" Grid.Row="1" Text="{Binding LastName}"></TextBox> |
|||
<Label Target="{Binding #bannedCheck}" Grid.Row="2" Grid.Column="0">_Banned</Label> |
|||
<CheckBox Name="bannedCheck" Grid.Column="2" Grid.Row="2" IsChecked="{Binding IsBanned}"></CheckBox> |
|||
<GridSplitter Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Grid.RowSpan="3" > |
|||
</GridSplitter> |
|||
<StackPanel Grid.Column="0" Grid.Row="4" Grid.ColumnSpan="3" Orientation="Horizontal" HorizontalAlignment="Right"> |
|||
<Button IsCancel="True" Command="{Binding #_labelsPage.DoCancel}">Cancel</Button> |
|||
<Button IsDefault="True" Command="{Binding #_labelsPage.DoSave}">Save</Button> |
|||
</StackPanel> |
|||
</Grid> |
|||
</ScrollViewer> |
|||
</UserControl> |
|||
@ -0,0 +1,43 @@ |
|||
using Avalonia; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Markup.Xaml; |
|||
using ControlCatalog.Models; |
|||
using ReactiveUI; |
|||
|
|||
namespace ControlCatalog.Pages |
|||
{ |
|||
public class LabelsPage : UserControl |
|||
{ |
|||
private Person _person; |
|||
|
|||
public LabelsPage() |
|||
{ |
|||
CreateDefaultPerson(); |
|||
this.InitializeComponent(); |
|||
} |
|||
|
|||
private void CreateDefaultPerson() |
|||
{ |
|||
DataContext = _person = new Person |
|||
{ |
|||
FirstName = "John", |
|||
LastName = "Doe", |
|||
IsBanned = true, |
|||
}; |
|||
} |
|||
|
|||
private void InitializeComponent() |
|||
{ |
|||
AvaloniaXamlLoader.Load(this); |
|||
} |
|||
|
|||
public void DoSave() |
|||
{ |
|||
|
|||
} |
|||
public void DoCancel() |
|||
{ |
|||
CreateDefaultPerson(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,74 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Text; |
|||
using Avalonia.Controls.Primitives; |
|||
using Avalonia.Controls.Templates; |
|||
using Avalonia.Data; |
|||
using Avalonia.Input; |
|||
using Avalonia.Interactivity; |
|||
|
|||
namespace Avalonia.Controls |
|||
{ |
|||
/// <summary>
|
|||
/// Label control. Focuses <see cref="Target"/> on pointer click or access key press (Alt + accessKey)
|
|||
/// </summary>
|
|||
public class Label : ContentControl |
|||
{ |
|||
/// <summary>
|
|||
/// Defines the <see cref="Target"/> Direct property
|
|||
/// </summary>
|
|||
public static readonly DirectProperty<Label, IInputElement> TargetProperty = |
|||
AvaloniaProperty.RegisterDirect<Label, IInputElement>(nameof(Target), lbl => lbl.Target, (lbl, inp) => lbl.Target = inp); |
|||
|
|||
/// <summary>
|
|||
/// Label focus target storage field
|
|||
/// </summary>
|
|||
private IInputElement _target; |
|||
|
|||
/// <summary>
|
|||
/// Label focus Target
|
|||
/// </summary>
|
|||
public IInputElement Target |
|||
{ |
|||
get => _target; |
|||
set => SetAndRaise(TargetProperty, ref _target, value); |
|||
} |
|||
|
|||
static Label() |
|||
{ |
|||
AccessKeyHandler.AccessKeyPressedEvent.AddClassHandler<Label>((lbl, args) => lbl.LabelActivated(args)); |
|||
// IsTabStopProperty.OverrideDefaultValue<Label>(false)
|
|||
FocusableProperty.OverrideDefaultValue<Label>(false); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes instance of <see cref="Label"/> control
|
|||
/// </summary>
|
|||
public Label() |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Method which focuses <see cref="Target"/> input element
|
|||
/// </summary>
|
|||
private void LabelActivated(RoutedEventArgs args) |
|||
{ |
|||
Target?.Focus(); |
|||
args.Handled = Target != null; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Handler of <see cref="IInputElement.PointerPressed"/> event
|
|||
/// </summary>
|
|||
/// <param name="e">Event Arguments</param>
|
|||
protected override void OnPointerPressed(PointerPressedEventArgs e) |
|||
{ |
|||
if (e.GetCurrentPoint(this).Properties.PointerUpdateKind == PointerUpdateKind.LeftButtonPressed) |
|||
{ |
|||
LabelActivated(e); |
|||
} |
|||
base.OnPointerPressed(e); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
<Style xmlns="https://github.com/avaloniaui" Selector="Label"> |
|||
<Setter Property="Padding" Value="3"/> |
|||
<Setter Property="Template"> |
|||
<ControlTemplate> |
|||
<ContentPresenter Name="PART_ContentPresenter" |
|||
Background="{TemplateBinding Background}" |
|||
BorderBrush="{TemplateBinding BorderBrush}" |
|||
BorderThickness="{TemplateBinding BorderThickness}" |
|||
ContentTemplate="{TemplateBinding ContentTemplate}" |
|||
Content="{TemplateBinding Content}" |
|||
Padding="{TemplateBinding Padding}" |
|||
RecognizesAccessKey="True" |
|||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" |
|||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"/> |
|||
</ControlTemplate> |
|||
</Setter> |
|||
</Style> |
|||
@ -0,0 +1,17 @@ |
|||
<Style xmlns="https://github.com/avaloniaui" Selector="Label"> |
|||
<Setter Property="Padding" Value="3"/> |
|||
<Setter Property="Template"> |
|||
<ControlTemplate> |
|||
<ContentPresenter Name="PART_ContentPresenter" |
|||
Background="{TemplateBinding Background}" |
|||
BorderBrush="{TemplateBinding BorderBrush}" |
|||
BorderThickness="{TemplateBinding BorderThickness}" |
|||
ContentTemplate="{TemplateBinding ContentTemplate}" |
|||
Content="{TemplateBinding Content}" |
|||
Padding="{TemplateBinding Padding}" |
|||
RecognizesAccessKey="True" |
|||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" |
|||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"/> |
|||
</ControlTemplate> |
|||
</Setter> |
|||
</Style> |
|||
Loading…
Reference in new issue