TargetNullValue, comment string Ensemble de fenêtres ressources [WPF]
-
25-09-2019 - |
Question
Salut, je voudrais mettre en valeur par défaut pour la liaison sur la propriété Text.
ressources veuves Je const des valeurs de chaîne:
<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>
Je cette liaison pour 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>
Le problème est que si la variable Info.Age est nulle, je WPF Texte propriété de la fenêtre ont une valeur « constAge » non « âge ». Prorties texte ont nom de la valeur sans valeur variable de type chaîne de variable de chaîne.
La solution
TargetNullValue="{StaticResource constSex}"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow