TargetNullValue、Windowsリソースから文字列を設定する方法[WPF]
-
25-09-2019 - |
質問
こんにちは、私は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がnullの場合は、問題は、I windowプロパティテキストWPFは値「constAge」ノー「年齢」を持っています。 Prortiesテキスト文字列変数の値の名前を文字列変数の値を持たない。
解決
TargetNullValue="{StaticResource constSex}"
所属していません StackOverflow