So I'm trying to Bind a TextBlock to multiple values on my Viewmodel (Mix of Enums and Strings). I have a DataTrigger that is supposed to fire when the text is null when returned by the Converter. But it doesn't! At first, I thought my Style didn't take hold (hence changed the Background on the Style to show it did). Anyway here is the code
XAML
<TextBlock x:Name="MyTextBlock" Grid.Column="2" Grid.ColumnSpan="3" VerticalAlignment="Center" DataContext="{StaticResource ViewModelLocator}"
Margin="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.BoldPadding), Mode=OneWay}">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource GeneralMultiStringDisplayConverter}">
<Binding Path="RatesViewModel.Instrument.Currency" NotifyOnSourceUpdated="True" UpdateSourceTrigger="PropertyChanged"/>
<Binding Path="RatesViewModel.Instrument.Underlying" NotifyOnSourceUpdated="True" UpdateSourceTrigger="PropertyChanged"/>
<Binding Path="RatesViewModel.Instrument.ProductType" NotifyOnSourceUpdated="True" UpdateSourceTrigger="PropertyChanged"/>
</MultiBinding>
</TextBlock.Text>
<TextBlock.Resources>
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource HeaderTextStyle}">
<Setter Property="Background" Value="Blue"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=MyTextBlock, Path=Text}" Value="{x:Null}"> <!--THIS SHOULD FIRE-->
<Setter Property="Text" Value="ThisShouldFireOnStart"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Resources>
</TextBlock>
The Converter is as follows:
class GeneralMultiStringDisplayConverter:IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var AS = DependencyProperty.UnsetValue;
if (values[0] != AS )
{
int count = values.Count();
string result = string.Empty;
for (int i = 0; i < count - 1; ++i)
{
try
{
var A = Enum.GetName((values[i].GetType()), values[i]);
result = String.Format("{0}{1}.", result, A);
}
catch (Exception ex)
{
result = String.Format("{0}{1}.", result, values[i]);
}
}
result = String.Format("{0}{1}", result, values[count - 1]);
return result;
}
return null;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
return null;
//TODO:
}
}
Debugging Steps that I have taken
`<Setter Property="Text" Value="ABC"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=MyTextBlock, Path=Text}" Value="ABC">
<Setter Property="Text" Value="ThisShouldFireOnStart"/>
</DataTrigger>
</Style.Triggers>
`
- Added a converter to the Styles DataTrigger Binding. It always gets "" as a parameter and not null for some reason. Setting the trigger Value to "" does not work.
Added a default Text property in the Style and tried changing the Value based off of that. (See example above)
I would appreciate some help in getting this to work Thanks!