Add LinkLabel control

This commit is contained in:
Michael Bucari-Tovo 2022-07-22 20:11:13 -06:00
parent 6aa0a1f8b9
commit 17b0da358f
5 changed files with 57 additions and 23 deletions

View File

@ -0,0 +1,13 @@
<TextBlock 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="800" d:DesignHeight="450"
x:Class="LibationWinForms.AvaloniaUI.Controls.LinkLabel">
<TextBlock.Styles>
<Style Selector="TextBlock">
<Setter Property="Foreground" Value="Blue"/>
<Setter Property="TextDecorations" Value="Underline"/>
</Style>
</TextBlock.Styles>
</TextBlock>

View File

@ -0,0 +1,34 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Markup.Xaml;
using Avalonia.Styling;
using System;
namespace LibationWinForms.AvaloniaUI.Controls
{
public partial class LinkLabel : TextBlock, IStyleable
{
Type IStyleable.StyleKey => typeof(TextBlock);
private static readonly Cursor HandCursor = new Cursor(StandardCursorType.Hand);
public LinkLabel()
{
InitializeComponent();
}
protected override void OnPointerEnter(PointerEventArgs e)
{
this.Cursor = HandCursor;
base.OnPointerEnter(e);
}
protected override void OnPointerLeave(PointerEventArgs e)
{
this.Cursor = Cursor.Default;
base.OnPointerLeave(e);
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}

View File

@ -23,18 +23,13 @@
</Panel>
<Panel Grid.Column="0" Grid.Row="1">
<Panel.Styles>
<Style Selector="TextBlock">
<Setter Property="Foreground" Value="Blue"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="TextDecorations" Value="Underline"/>
</Style>
</Panel.Styles>
<TextBlock
Margin="10" TextWrapping="Wrap" TextAlignment="Center"
Tapped="GoToAudible_Tapped"
Text="Open in&#xa;Audible&#xa;(Browser)" />
<controls:LinkLabel
Margin="10"
TextWrapping="Wrap"
TextAlignment="Center"
Tapped="GoToAudible_Tapped"
Text="Open in&#xa;Audible&#xa;(Browser)" />
</Panel>
<TextBox

View File

@ -6,6 +6,7 @@
MinWidth="350" MinHeight="200"
Width="350" Height="200"
WindowStartupLocation="CenterOwner"
xmlns:controls="clr-namespace:LibationWinForms.AvaloniaUI.Controls"
x:Class="LibationWinForms.AvaloniaUI.Views.Dialogs.Login.LoginChoiceEagerDialog"
Title="Audible Login"
Icon="/AvaloniaUI/Assets/libation.ico" >
@ -51,9 +52,7 @@
Grid.Row="3"
VerticalAlignment="Bottom">
<TextBlock
Foreground="Blue"
TextDecorations="Underline"
<controls:LinkLabel
Tapped="ExternalLoginLink_Tapped"
Text="Or click here to log in with your browser." />

View File

@ -6,6 +6,7 @@
MinWidth="600" MinHeight="450"
MaxWidth="600" MaxHeight="450"
x:Class="LibationWinForms.AvaloniaUI.Views.Dialogs.MessageBoxAlertAdminDialog"
xmlns:controls="clr-namespace:LibationWinForms.AvaloniaUI.Controls"
Title="MessageBoxAlertAdminDialog"
WindowStartupLocation="CenterOwner"
Icon="/AvaloniaUI/Assets/libation.ico">
@ -47,16 +48,8 @@
HorizontalAlignment="Center"
VerticalAlignment="Center"
Orientation="Vertical">
<StackPanel.Styles>
<Style Selector="TextBlock">
<Setter Property="Foreground" Value="Blue"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="TextDecorations" Value="Underline"/>
</Style>
</StackPanel.Styles>
<TextBlock
<controls:LinkLabel
Margin="10"
Tapped="GoToGithub_Tapped"
Text="Click to go to github" />