mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-04-04 20:59:05 +00:00
Migrate to Avalonia (#1220)
This commit is contained in:
19
DiscordChatExporter.Gui/Views/Controls/HyperLink.axaml
Normal file
19
DiscordChatExporter.Gui/Views/Controls/HyperLink.axaml
Normal file
@@ -0,0 +1,19 @@
|
||||
<UserControl
|
||||
x:Class="DiscordChatExporter.Gui.Views.Controls.HyperLink"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<TextBlock
|
||||
x:Name="TextBlock"
|
||||
Cursor="Hand"
|
||||
Foreground="{DynamicResource MaterialSecondaryDarkBrush}"
|
||||
PointerReleased="TextBlock_OnPointerReleased"
|
||||
Text="{Binding $parent[UserControl].Text, Mode=OneWay}">
|
||||
<TextBlock.Styles>
|
||||
<Style Selector="TextBlock">
|
||||
<Style Selector="^:pointerover">
|
||||
<Setter Property="TextDecorations" Value="Underline" />
|
||||
</Style>
|
||||
</Style>
|
||||
</TextBlock.Styles>
|
||||
</TextBlock>
|
||||
</UserControl>
|
||||
49
DiscordChatExporter.Gui/Views/Controls/HyperLink.axaml.cs
Normal file
49
DiscordChatExporter.Gui/Views/Controls/HyperLink.axaml.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Windows.Input;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
|
||||
namespace DiscordChatExporter.Gui.Views.Controls;
|
||||
|
||||
public partial class HyperLink : UserControl
|
||||
{
|
||||
public static readonly StyledProperty<string?> TextProperty =
|
||||
TextBlock.TextProperty.AddOwner<HyperLink>();
|
||||
|
||||
public static readonly StyledProperty<ICommand?> CommandProperty =
|
||||
Button.CommandProperty.AddOwner<HyperLink>();
|
||||
|
||||
public static readonly StyledProperty<object?> CommandParameterProperty =
|
||||
Button.CommandParameterProperty.AddOwner<HyperLink>();
|
||||
|
||||
public HyperLink() => InitializeComponent();
|
||||
|
||||
public string? Text
|
||||
{
|
||||
get => GetValue(TextProperty);
|
||||
set => SetValue(TextProperty, value);
|
||||
}
|
||||
|
||||
public ICommand? Command
|
||||
{
|
||||
get => GetValue(CommandProperty);
|
||||
set => SetValue(CommandProperty, value);
|
||||
}
|
||||
|
||||
public object? CommandParameter
|
||||
{
|
||||
get => GetValue(CommandParameterProperty);
|
||||
set => SetValue(CommandParameterProperty, value);
|
||||
}
|
||||
|
||||
private void TextBlock_OnPointerReleased(object? sender, PointerReleasedEventArgs args)
|
||||
{
|
||||
if (Command is null)
|
||||
return;
|
||||
|
||||
if (!Command.CanExecute(CommandParameter))
|
||||
return;
|
||||
|
||||
Command.Execute(CommandParameter);
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
<UserControl
|
||||
x:Class="DiscordChatExporter.Gui.Views.Controls.RevealablePasswordBox"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
x:Name="Root"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<TextBox
|
||||
materialDesign:TextFieldAssist.DecorationVisibility="Hidden"
|
||||
BorderThickness="{Binding BorderThickness, ElementName=Root}"
|
||||
Text="{Binding Password, ElementName=Root, UpdateSourceTrigger=PropertyChanged}"
|
||||
Visibility="{Binding IsRevealed, ElementName=Root, Converter={x:Static s:BoolToVisibilityConverter.Instance}}" />
|
||||
<PasswordBox
|
||||
materialDesign:PasswordBoxAssist.Password="{Binding Password, ElementName=Root, UpdateSourceTrigger=PropertyChanged}"
|
||||
materialDesign:TextFieldAssist.DecorationVisibility="Hidden"
|
||||
BorderThickness="{Binding BorderThickness, ElementName=Root}"
|
||||
IsEnabled="False"
|
||||
Visibility="{Binding IsRevealed, ElementName=Root, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}}" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -1,40 +0,0 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace DiscordChatExporter.Gui.Views.Controls;
|
||||
|
||||
public partial class RevealablePasswordBox
|
||||
{
|
||||
public static readonly DependencyProperty PasswordProperty = DependencyProperty.Register(
|
||||
nameof(Password),
|
||||
typeof(string),
|
||||
typeof(RevealablePasswordBox),
|
||||
new FrameworkPropertyMetadata(
|
||||
string.Empty,
|
||||
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault
|
||||
)
|
||||
);
|
||||
|
||||
public static readonly DependencyProperty IsRevealedProperty = DependencyProperty.Register(
|
||||
nameof(IsRevealed),
|
||||
typeof(bool),
|
||||
typeof(RevealablePasswordBox),
|
||||
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.None)
|
||||
);
|
||||
|
||||
public string Password
|
||||
{
|
||||
get => (string)GetValue(PasswordProperty);
|
||||
set => SetValue(PasswordProperty, value);
|
||||
}
|
||||
|
||||
public bool IsRevealed
|
||||
{
|
||||
get => (bool)GetValue(IsRevealedProperty);
|
||||
set => SetValue(IsRevealedProperty, value);
|
||||
}
|
||||
|
||||
public RevealablePasswordBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user