【问题标题】:TargetNullValue, how set string from windows resource[WPF]TargetNullValue,如何从 windows 资源中设置字符串[WPF]
【发布时间】:2011-05-23 01:17:25
【问题描述】:

您好,我想为 Text 属性的绑定设置默认值。

在寡妇资源中,我有 const 字符串值:

<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”而不是“Age”。 Prorties 文本有字符串变量的值名称没有字符串变量的值。

【问题讨论】:

    标签: wpf targetnullvalue


    【解决方案1】:
    TargetNullValue="{StaticResource constSex}"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-10
      相关资源
      最近更新 更多