wpftargetnullvalue

TargetNullValue, how set string from windows resource[WPF]


Hi I would like set default value for binding on Text property.

In widows resources I have const string values:

<Window.Resources>
    <sys:String x:Key="constSex">Pohlavie</sys:String>
    <sys:String x:Key="constAge">Age</sys:String>
    <sys:String x:Key="constRegion">Region</sys:String>
    <sys:String x:Key="constCity">Mesto</sys:String>
    <sys:String x:Key="constPhotoAlbums">Fotoalbumov: 0</sys:String>
    <sys:String x:Key="constVideoAlbums">Videoalbumov :0</sys:String>
</Window.Resources>

I have this binding for TextBlock:

        <TextBlock Style="{StaticResource InfosStyle2}" Width="160" Grid.Row="0" HorizontalAlignment="Left">
            <TextBlock.Text>
                <MultiBinding StringFormat="{}{0}, {1}">
                    <Binding Path="Info.Sex" TargetNullValue="constSex" Mode="OneWay" UpdateSourceTrigger="PropertyChanged" Converter="{StaticResource sexConvertor}" />
                    <Binding Path="Info.Age" TargetNullValue="constAge" Mode="OneWay" UpdateSourceTrigger="PropertyChanged"/>                            
                </MultiBinding>
            </TextBlock.Text>
        </TextBlock>

Problem is if variable Info.Age is null, I wpf window property Text have value "constAge" no "Age". Prorties Text have value name of string variable no value of string variable.


Solution

  • TargetNullValue="{StaticResource constSex}"