mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-03-16 20:02:42 +00:00
Hide token using password box
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<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}"
|
||||
Visibility="{Binding IsRevealed, ElementName=Root, Converter={x:Static s:BoolToVisibilityConverter.Instance}}" />
|
||||
<PasswordBox
|
||||
x:Name="PasswordBox"
|
||||
materialDesign:TextFieldAssist.DecorationVisibility="Hidden"
|
||||
BorderThickness="{Binding BorderThickness, ElementName=Root}"
|
||||
PasswordChanged="PasswordBox_OnPasswordChanged"
|
||||
Visibility="{Binding IsRevealed, ElementName=Root, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}}" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,50 @@
|
||||
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,
|
||||
(sender, args) =>
|
||||
{
|
||||
var revealablePasswordBox = (RevealablePasswordBox)sender;
|
||||
var password = (string)args.NewValue;
|
||||
|
||||
revealablePasswordBox.PasswordBox.Password = password;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
private void PasswordBox_OnPasswordChanged(object sender, RoutedEventArgs args) =>
|
||||
Password = PasswordBox.Password;
|
||||
}
|
||||
Reference in New Issue
Block a user