XAML
<StackPanel>
<TextBlock Text="AAA" Margin="4"/>
<TextBlock Text="{Binding TextString}" Margin="4"/>
<Button Content="Click" Click="Button_Click"/>
</StackPanel>
View Model
public class ViewModel : BindingObject
{
private string mTextString;
public string TextString { get => mTextString; set => OnPropertyChanged(ref mTextString, value); }
public ViewModel()
{
TextString = "BBB";
}
public void OnClick()
{
if (TextString == "BBB")
{
TextString = "CCC";
}
else
{
TextString = "BBB";
}
}
}
Converter
public class ConvertTextInTextBlock : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value; // Break Point Here
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
}
ResourceDictionary
<ResourceDictionary
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TextConverterTest"
mc:Ignorable="d">
<local:ConvertTextInTextBlock x:Key="convertTextInTextBlock"/>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Text" Value="{Binding RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource convertTextInTextBlock}}"/>
</Style>
</ResourceDictionary>
Click을 통해 TextString을 업데이트했으나 Converter에 값이 전달되지 않을을 Debug를 통해서 확인했습니다.
개념적인 이해도가 아직 부족해서 문제의 원인을 알 수 없습니다.
도움을 부탁 드립니다.