TargetNullValue, come impostare stringa dalla risorsa finestre [WPF]
-
25-09-2019 - |
Domanda
Ciao vorrei valore impostato di default per la rilegatura sulla proprietà Text.
In vedove risorse ho valori const string:
<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>
Ho questo vincolante per 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>
Il problema è se Info.Age variabile è nulla, ho WPF finestra di proprietà di testo hanno un valore "constAge" no "Age". Prorties testo hanno nome del valore della variabile stringa nessun valore della variabile stringa.
Soluzione
TargetNullValue="{StaticResource constSex}"
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow