Natriss
Natriss
CC#
Created by Natriss on 3/1/2024 in #help
Binding and DependencyProperty
Generic.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ValidationTest"
xmlns:controls="using:ValidationTest.Controls">

<Style TargetType="controls:ValidationTextBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:ValidationTextBox">
<Grid ColumnSpacing="12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<TextBox x:Name="TextBox" Grid.Column="0" Header="Test" Text="{TemplateBinding Text}" Description="Test" PlaceholderText="Test" />
<FontIcon x:Name="ErrorIcon" Grid.Column="1" Glyph="&#xE814;" Foreground="Orange" Visibility="Visible" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ValidationTest"
xmlns:controls="using:ValidationTest.Controls">

<Style TargetType="controls:ValidationTextBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:ValidationTextBox">
<Grid ColumnSpacing="12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<TextBox x:Name="TextBox" Grid.Column="0" Header="Test" Text="{TemplateBinding Text}" Description="Test" PlaceholderText="Test" />
<FontIcon x:Name="ErrorIcon" Grid.Column="1" Glyph="&#xE814;" Foreground="Orange" Visibility="Visible" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
ValidationTextBox.cs
public sealed class ValidationTextBox : Control
{
public ValidationTextBox()
{
this.DefaultStyleKey = typeof(ValidationTextBox);
}

public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}

public static readonly DependencyProperty TextProperty = DependencyProperty.Register(nameof(Text), typeof(string), typeof(ValidationTextBox), new PropertyMetadata(default(string)));
}
public sealed class ValidationTextBox : Control
{
public ValidationTextBox()
{
this.DefaultStyleKey = typeof(ValidationTextBox);
}

public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}

public static readonly DependencyProperty TextProperty = DependencyProperty.Register(nameof(Text), typeof(string), typeof(ValidationTextBox), new PropertyMetadata(default(string)));
}
For some reason he doesn't do these Mode=TwoWay, UpdateSourceTrigger=PropertyChanged. <controls:ValidationTextBox Text="{x:Bind ViewModel.Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> What am I doing wrong here? I followed this https://learn.microsoft.com/en-us/windows/apps/winui/winui3/xaml-templated-controls-csharp-winui-3
1 replies
CC#
Created by Natriss on 8/6/2023 in #help
graphUser almost fully NULL - Graph API
2 replies