converter fix

This commit is contained in:
2023-07-04 15:21:19 +09:00
parent de76ae38b4
commit 1a082fe79c
2 changed files with 5 additions and 5 deletions

View File

@@ -15,10 +15,10 @@ namespace BindingValidationRuleSample.Converter
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (targetType != typeof(Brush))
return null;
return Brushes.Black;
if (value == null)
return null;
return Brushes.Black;
int age = int.Parse(value.ToString());
return ValueColor(age);

View File

@@ -38,7 +38,8 @@
<TextBox Grid.Column="1" Grid.Row="0" Margin="5"
Text="{Binding Name, Mode=TwoWay}"/>
<TextBox x:Name="tbxAge" Grid.Column="1" Grid.Row="1" Margin="5"
ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}">
ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"
Foreground="{Binding Path=Age, Mode=TwoWay, Converter={StaticResource cvtAgeToBrush}}">
<TextBox.Text>
<Binding Path="Age"
Mode="TwoWay"
@@ -49,8 +50,7 @@
</Binding>
</TextBox.Text>
</TextBox>
<TextBox Grid.Column="1" Grid.Row="2" Margin="5"
Foreground="{Binding Path=Age, Mode=TwoWay, Converter={StaticResource cvtAgeToBrush}}"
<TextBox Grid.Column="1" Grid.Row="2" Margin="5" Foreground="Blue"
Text="{Binding PhoneNumber, Mode=TwoWay}"/>
<Grid Grid.Column="0" Grid.Row="4" Grid.ColumnSpan="2" Height="30">