Ellen Joe.♡
Ellen Joe.♡
CC#
Created by Ellen Joe.♡ on 8/21/2024 in #help
✅ How to get data out of a custom control?
Currently, I'm doing a custom user control for a password box with a label showcasing what to put in there. Right now, this is the content of my user control:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Content="{Binding LabelText, ElementName=root}" Height="24" Margin="0 0 0 5" Grid.Column="0"/>
<PasswordBox Width="200" Height="24" Password="{Binding Password, ElementName=root}" Grid.Column="1"/>
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Content="{Binding LabelText, ElementName=root}" Height="24" Margin="0 0 0 5" Grid.Column="0"/>
<PasswordBox Width="200" Height="24" Password="{Binding Password, ElementName=root}" Grid.Column="1"/>
</Grid>
And this is the .cs file:
using System.Windows;
using System.Windows.Controls;

namespace WoWSpect.Components;

public partial class PasswordBoxWithLabel : UserControl
{
public static readonly DependencyProperty LabelTextProperty = DependencyProperty.Register(
nameof(LabelTextProperty), typeof(string), typeof(PasswordBoxWithLabel), new PropertyMetadata(string.Empty));

public static readonly DependencyProperty PasswordProperty = DependencyProperty.Register(
nameof(Password), typeof(string), typeof(PasswordBoxWithLabel), new PropertyMetadata(string.Empty));

public string Password
{
get { return (string)GetValue(PasswordProperty); }
set { SetValue(PasswordProperty, value); }
}

public string LabelText
{
get { return (string)GetValue(LabelTextProperty); }
set { SetValue(LabelTextProperty, value); }
}

public PasswordBoxWithLabel()
{
InitializeComponent();
}
}
using System.Windows;
using System.Windows.Controls;

namespace WoWSpect.Components;

public partial class PasswordBoxWithLabel : UserControl
{
public static readonly DependencyProperty LabelTextProperty = DependencyProperty.Register(
nameof(LabelTextProperty), typeof(string), typeof(PasswordBoxWithLabel), new PropertyMetadata(string.Empty));

public static readonly DependencyProperty PasswordProperty = DependencyProperty.Register(
nameof(Password), typeof(string), typeof(PasswordBoxWithLabel), new PropertyMetadata(string.Empty));

public string Password
{
get { return (string)GetValue(PasswordProperty); }
set { SetValue(PasswordProperty, value); }
}

public string LabelText
{
get { return (string)GetValue(LabelTextProperty); }
set { SetValue(LabelTextProperty, value); }
}

public PasswordBoxWithLabel()
{
InitializeComponent();
}
}
But as soon as I use it somewhere to display something, I get this error: System.Windows.Markup.XamlParseException: A 'Binding' cannot be set on the 'Password' property of type 'PasswordBox'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject. How can I fix it? I need to get the password out of the password box from my user control, but since I cannot use a property apparently, I don't know another way to do it.
100 replies
CC#
Created by Ellen Joe.♡ on 8/20/2024 in #help
Specific radio button style in WPF
No description
2 replies
CC#
Created by Ellen Joe.♡ on 7/16/2024 in #help
Bevel effect in Style Template
No description
5 replies
CC#
Created by Ellen Joe.♡ on 5/31/2024 in #help
Cannot find method although defined and used?
I'm currently creating a WPF project and have this static class:
namespace KupoFinder.AppConfigHandler;

public static class AppConfigHandler
{
private const string ConfigFileName = "KupoFinder.settings.json";

public static void CheckConfigFile(){}

// ...
}
namespace KupoFinder.AppConfigHandler;

public static class AppConfigHandler
{
private const string ConfigFileName = "KupoFinder.settings.json";

public static void CheckConfigFile(){}

// ...
}
And I use it in my ViewModel like this:
using CommunityToolkit.Mvvm.ComponentModel;
using KupoFinder.AppConfigHandler;

namespace KupoFinder.MVVM;

public partial class MainWindowVM : ObservableObject
{
public MainWindowVM()
{
AppConfigHandler.CheckConfigFile();
}
}
using CommunityToolkit.Mvvm.ComponentModel;
using KupoFinder.AppConfigHandler;

namespace KupoFinder.MVVM;

public partial class MainWindowVM : ObservableObject
{
public MainWindowVM()
{
AppConfigHandler.CheckConfigFile();
}
}
But I get the error: Cannot resolve symbol 'CheckConfigFile' It should find it tho cuz my VM has a dependency on it. Does anyone see the error?
3 replies