I have this kind of code below, how can I bind the visibility of the Border to the visibility of all the labels?
Of course the number of rows and labels is not fixed.
<Border BorderBrush=Black
BorderThickness="1,1,1,1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label DataContext="{Binding MyObject[1]}"
Content="{Binding MyText}"
Visibility="{Binding IsVisible}"/>
<Label DataContext="{Binding MyObject[2]}"
Content="{Binding MyText}"
Visibility="{Binding IsVisible}"/>
[...]
</Grid>
</Border>
It depends on how you are changing the amount of rows and labels.
I assume that
MyObjectis aList<MyObject>. In that case what you can do is simply bind the list to theVisibilityproperty with aConverterthat loops through the objects checking if they are all invisible.XAML:
Namespace:
Window:
Converters Code:
Otherwise you are going to have to explain how you got the amount of rows and labels to be dynamic and we can work from there.
Hope this helps
u_u
EDIT
Well according to your comment you have a list of strings which contain the name of the object you want to display in each
ListViewItem. I’m not going to ask why you are doing it this way, I assume you have a reason. I just wanna say have you tried Key Value pairs?What I would do here is pass the grid itself as a parameter in the converter, and loop through its children using a LogicalTreeHelper inside the converter.
Revised Border:
Revised Converter
I coded this all by hand so there’s prolly a bunch of errors, but I hope you get the point.
u_u