문제

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.

도움이 되었습니까?

해결책

TargetNullValue="{StaticResource constSex}"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top