Ellen Joe.♡
Ellen Joe.♡
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
Yea, but I use the password box just to hide it from the user in case they are streaming. That's the only reason I use it
100 replies
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
I found a different fix with a helper class which is basically creating a copy of the password and attaching it to the password on load
public static class PasswordHelper
{
public static readonly DependencyProperty PasswordProperty = DependencyProperty.RegisterAttached("Password",
typeof(string), typeof(PasswordHelper), new FrameworkPropertyMetadata(string.Empty, OnPasswordPropertyChanged));

public static readonly DependencyProperty AttachProperty = DependencyProperty.RegisterAttached("Attach",
typeof(bool), typeof(PasswordHelper), new FrameworkPropertyMetadata(false, Attach));

public static readonly DependencyProperty IsUpdatingProperty = DependencyProperty.RegisterAttached("IsUpdating",
typeof(bool), typeof(PasswordHelper));

public static void SetAttach(DependencyObject dp, bool value)
{
dp.SetValue(AttachProperty, value);
}

public static bool GetAttach(DependencyObject dp)
{
return (bool) dp.GetValue(AttachProperty);
}

public static void SetPassword(DependencyObject dp, string value)
{
dp.SetValue(PasswordProperty, value);
}

public static string GetPassword(DependencyObject dp)
{
return (string)dp.GetValue(PasswordProperty);
}

public static void SetIsUpdating(DependencyObject dp, bool value)
{
dp.SetValue(IsUpdatingProperty, value);
}

public static bool GetIsUpdating(DependencyObject dp)
{
return (bool) dp.GetValue(IsUpdatingProperty);
}

private static void OnPasswordPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
{
if(sender is not PasswordBox passwordBox) return;

passwordBox.PasswordChanged -= PasswordBox_PasswordChanged;

if(!GetIsUpdating(passwordBox))
{
passwordBox.Password = (string) args.NewValue;
}

passwordBox.PasswordChanged += PasswordBox_PasswordChanged;
}

private static void Attach(DependencyObject sender, DependencyPropertyChangedEventArgs args)
{
if(sender is not PasswordBox passwordBox) return;

if((bool) args.OldValue)
{
passwordBox.PasswordChanged -= PasswordBox_PasswordChanged;
}

if((bool) args.NewValue)
{
passwordBox.PasswordChanged += PasswordBox_PasswordChanged;
}

}

private static void PasswordBox_PasswordChanged(object sender, RoutedEventArgs args)
{
if(sender is not PasswordBox passwordBox) return;

SetIsUpdating(passwordBox, true);

SetPassword(passwordBox, passwordBox.Password);

SetIsUpdating(passwordBox, false);
}
}
public static class PasswordHelper
{
public static readonly DependencyProperty PasswordProperty = DependencyProperty.RegisterAttached("Password",
typeof(string), typeof(PasswordHelper), new FrameworkPropertyMetadata(string.Empty, OnPasswordPropertyChanged));

public static readonly DependencyProperty AttachProperty = DependencyProperty.RegisterAttached("Attach",
typeof(bool), typeof(PasswordHelper), new FrameworkPropertyMetadata(false, Attach));

public static readonly DependencyProperty IsUpdatingProperty = DependencyProperty.RegisterAttached("IsUpdating",
typeof(bool), typeof(PasswordHelper));

public static void SetAttach(DependencyObject dp, bool value)
{
dp.SetValue(AttachProperty, value);
}

public static bool GetAttach(DependencyObject dp)
{
return (bool) dp.GetValue(AttachProperty);
}

public static void SetPassword(DependencyObject dp, string value)
{
dp.SetValue(PasswordProperty, value);
}

public static string GetPassword(DependencyObject dp)
{
return (string)dp.GetValue(PasswordProperty);
}

public static void SetIsUpdating(DependencyObject dp, bool value)
{
dp.SetValue(IsUpdatingProperty, value);
}

public static bool GetIsUpdating(DependencyObject dp)
{
return (bool) dp.GetValue(IsUpdatingProperty);
}

private static void OnPasswordPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
{
if(sender is not PasswordBox passwordBox) return;

passwordBox.PasswordChanged -= PasswordBox_PasswordChanged;

if(!GetIsUpdating(passwordBox))
{
passwordBox.Password = (string) args.NewValue;
}

passwordBox.PasswordChanged += PasswordBox_PasswordChanged;
}

private static void Attach(DependencyObject sender, DependencyPropertyChangedEventArgs args)
{
if(sender is not PasswordBox passwordBox) return;

if((bool) args.OldValue)
{
passwordBox.PasswordChanged -= PasswordBox_PasswordChanged;
}

if((bool) args.NewValue)
{
passwordBox.PasswordChanged += PasswordBox_PasswordChanged;
}

}

private static void PasswordBox_PasswordChanged(object sender, RoutedEventArgs args)
{
if(sender is not PasswordBox passwordBox) return;

SetIsUpdating(passwordBox, true);

SetPassword(passwordBox, passwordBox.Password);

SetIsUpdating(passwordBox, false);
}
}
100 replies
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
Alright, I'ma take a break from coding in the meantime
100 replies
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
Should be in this link in TextBoxes.xaml
100 replies
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
(In the Application resources)
100 replies
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
<Color x:Key="TextColor">#f8cb00</Color>
<SolidColorBrush x:Key="TextColorBrush" Color="{StaticResource TextColor}"/>
<Color x:Key="TextColor">#f8cb00</Color>
<SolidColorBrush x:Key="TextColorBrush" Color="{StaticResource TextColor}"/>
100 replies
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
And here is the MainWindowVM https://paste.mod.gg/gsaczheztbgq/0
100 replies
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
I dont know how to rename the first file, but the first one (newfile) is the Buttons.xaml
100 replies
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
100 replies
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
Sure
100 replies
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
<UserControl x:Class="WoWSpect.MVVM.Views.SettingsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WoWSpect.MVVM.Views"
xmlns:viewModels="clr-namespace:WoWSpect.MVVM.ViewModels"
xmlns:components="clr-namespace:WoWSpect.Components"
mc:Ignorable="d"
d:DesignHeight="570" d:DesignWidth="675"
d:Background="DimGray">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ResourceDictionaries/Buttons.xaml"/>
<ResourceDictionary Source="/ResourceDictionaries/Texts.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<UserControl.DataContext>
<viewModels:SettingsVM />
</UserControl.DataContext>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="Auto"/>
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<TextBlock Grid.Row="0"
Margin="20 5 0 0"
FontSize="18"
Foreground="White">Settings</TextBlock>
<Border Grid.Row="1" Height="1" Opacity="0.5" Margin="0 5 0 0 ">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="Transparent" Offset="0"/>
<GradientStop Color="#484b47" Offset="0.2"/>
<GradientStop Color="#484b47" Offset="0.6"/>
<GradientStop Color="Transparent" Offset="0.8"/>
</LinearGradientBrush>
</Border.Background>
</Border>
<ScrollViewer Grid.Row="2" VerticalScrollBarVisibility="Auto">
<StackPanel Margin="40 5 0 0">
<components:PasswordBoxWithLabel LabelText="Client ID"
LabelColor="{StaticResource TextColorBrush}"
Password="{Binding ClientID, Mode=TwoWay }"
Margin="0 10 0 0"/>
<components:PasswordBoxWithLabel LabelText="Client Secret"
LabelColor="{StaticResource TextColorBrush}"
Password="{Binding ClientSecret, Mode=TwoWay }"
Margin="0 10 0 0"/>
<Grid Margin="0 50 0 0">
<Button Style="{StaticResource InteractionButton}"
Width="100"
Height="30"
Margin="200 30 0 0"
Command="{Binding SaveSettingsCommand}">
Save
</Button>
</Grid>
</StackPanel>
</ScrollViewer>
</Grid>
</UserControl>
<UserControl x:Class="WoWSpect.MVVM.Views.SettingsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WoWSpect.MVVM.Views"
xmlns:viewModels="clr-namespace:WoWSpect.MVVM.ViewModels"
xmlns:components="clr-namespace:WoWSpect.Components"
mc:Ignorable="d"
d:DesignHeight="570" d:DesignWidth="675"
d:Background="DimGray">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ResourceDictionaries/Buttons.xaml"/>
<ResourceDictionary Source="/ResourceDictionaries/Texts.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<UserControl.DataContext>
<viewModels:SettingsVM />
</UserControl.DataContext>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="Auto"/>
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<TextBlock Grid.Row="0"
Margin="20 5 0 0"
FontSize="18"
Foreground="White">Settings</TextBlock>
<Border Grid.Row="1" Height="1" Opacity="0.5" Margin="0 5 0 0 ">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="Transparent" Offset="0"/>
<GradientStop Color="#484b47" Offset="0.2"/>
<GradientStop Color="#484b47" Offset="0.6"/>
<GradientStop Color="Transparent" Offset="0.8"/>
</LinearGradientBrush>
</Border.Background>
</Border>
<ScrollViewer Grid.Row="2" VerticalScrollBarVisibility="Auto">
<StackPanel Margin="40 5 0 0">
<components:PasswordBoxWithLabel LabelText="Client ID"
LabelColor="{StaticResource TextColorBrush}"
Password="{Binding ClientID, Mode=TwoWay }"
Margin="0 10 0 0"/>
<components:PasswordBoxWithLabel LabelText="Client Secret"
LabelColor="{StaticResource TextColorBrush}"
Password="{Binding ClientSecret, Mode=TwoWay }"
Margin="0 10 0 0"/>
<Grid Margin="0 50 0 0">
<Button Style="{StaticResource InteractionButton}"
Width="100"
Height="30"
Margin="200 30 0 0"
Command="{Binding SaveSettingsCommand}">
Save
</Button>
</Grid>
</StackPanel>
</ScrollViewer>
</Grid>
</UserControl>
100 replies
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
I can post my usercontrol xml here if it might help
100 replies
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
I unfortunately cannot because it's for an academic assignment and it will look very weird when other people are also in there :'D
100 replies
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
It is, but it's a private repository currently
100 replies
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
It's removed and it's still being called
100 replies
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using WoWSpect.ConfigHandler;

public partial class SettingsVM : ObservableObject
{
[ObservableProperty]
private string _clientID;

[ObservableProperty]
private string _clientSecret;


public SettingsVM()
{
LoadSettings();
}

public void LoadSettings()
{
string[] keys = [AppConfigHandler.ClientIdKey, AppConfigHandler.ClientSecretKey];

if (AppConfigHandler.TryGetValues(keys, out IDictionary<string, string> values))
{
ClientID = values.TryGetValue(AppConfigHandler.ClientIdKey, out string clientId) ? clientId : string.Empty;
ClientSecret = values.TryGetValue(AppConfigHandler.ClientSecretKey, out string clientSecret) ? clientSecret : string.Empty;
}
else
{
ClientID = string.Empty;
ClientSecret = string.Empty;
}
}

[RelayCommand]
private void SaveSettings()
{
Dictionary<string, string> values = new Dictionary<string, string>
{
[AppConfigHandler.ClientIdKey] = ClientID,
[AppConfigHandler.ClientSecretKey] = ClientSecret
};

AppConfigHandler.SetValues(values);
}
}
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using WoWSpect.ConfigHandler;

public partial class SettingsVM : ObservableObject
{
[ObservableProperty]
private string _clientID;

[ObservableProperty]
private string _clientSecret;


public SettingsVM()
{
LoadSettings();
}

public void LoadSettings()
{
string[] keys = [AppConfigHandler.ClientIdKey, AppConfigHandler.ClientSecretKey];

if (AppConfigHandler.TryGetValues(keys, out IDictionary<string, string> values))
{
ClientID = values.TryGetValue(AppConfigHandler.ClientIdKey, out string clientId) ? clientId : string.Empty;
ClientSecret = values.TryGetValue(AppConfigHandler.ClientSecretKey, out string clientSecret) ? clientSecret : string.Empty;
}
else
{
ClientID = string.Empty;
ClientSecret = string.Empty;
}
}

[RelayCommand]
private void SaveSettings()
{
Dictionary<string, string> values = new Dictionary<string, string>
{
[AppConfigHandler.ClientIdKey] = ClientID,
[AppConfigHandler.ClientSecretKey] = ClientSecret
};

AppConfigHandler.SetValues(values);
}
}
100 replies
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
But the view does not get the updated properties
100 replies
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
Yes
100 replies
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
Yes, that method is working
100 replies
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
With the corresponding data for ClientID and ClientSecret
100 replies