您好我想设定默认值用于在文本属性绑定。

在寡妇资源我有常量字符串值:

<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>

我此绑定为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>

问题是,如果可变Info.Age为空,我WPF窗口属性Text具有值“constAge”否“年龄”。 Prorties文本有字符串变量值名称没有字符串变量的值。

有帮助吗?

解决方案

TargetNullValue="{StaticResource constSex}"
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top