DataBind a Control for another control

I have two converters, one sets the visibility of the control to Hidden if the text is null. Another converts int to string. I am trying to use both of them below, I want to make the DockPanel Hidden if tbDisposition.Text is null, but the DockPanel binding does not work a bit.

<DockPanel Visibility="{Binding Path=tbDisposition.Text, Converter={StaticResource cIsVisible}}"> <TextBlock Text="Disposition: "/> <TextBlock Name="tbDisposition" Text="{Binding Path=SessionEvent.DispositionID, Converter={BLL:CodeMarkupExtension}}" Foreground="Blue" /> </DockPanel> 
+4
source share
2 answers

You need to use ElementName :

 <DockPanel Visibility="{Binding ElementName=tbDisposition, Path=Text, Converter={StaticResource cIsVisible}}"> <TextBlock Text="Disposition: "/> <TextBlock Name="tbDisposition" Text="{Binding Path=SessionEvent.DispositionID, Converter={BLL:CodeMarkupExtension}}" Foreground="Blue" /> </DockPanel> 
+3
source

When binding objects to the Text property, ToString() automatically called on this object, so there is no need for an int to string converter. Instead, you can simply override ToString.

0
source

All Articles