Search code examples
windows-phone-7textblocklistboxitem

How to set a visibility of TextBlock bound to a ListBox?


How can I set a TextBlock visibility inside a ListBox. For example

<Grid>
   <ListBox Name="myList">
     <ListBox.ItemTemplate>
          <DataTemplate>
             <TextBloxk Name="txtBlock1" Text="{Binding} First Name">
             <TextBloxk Name="txtBlock2" Text="{Binding} Last Name">
          </DataTemplate>
     </ListBox.ItemTemplate>
   </ListBox>
</Grid>

At run time, I want to set the visibility of either textblocks to either Visible or Collapsed.

How can I do that, or can I?


Solution

  • You can use BooleanToVisibilityConverter (or other, custom converter) to change the Visibility according to binding value.