Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7713177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:48:28+00:00 2026-06-01T01:48:28+00:00

I have this kind of code below, how can I bind the visibility of

  • 0

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:48:30+00:00Added an answer on June 1, 2026 at 1:48 am

    It depends on how you are changing the amount of rows and labels.

    I assume that MyObject is a List<MyObject>. In that case what you can do is simply bind the list to the Visibility property with a Converter that loops through the objects checking if they are all invisible.

    XAML:

    Namespace:

    xmlns:converters="clr-namespace:MyConverters"    
    

    Window:

    <Window.Resources>
        <converters:ObjectBorderVisibilityConverter 
                   x:Key="MyObjectBorderVisibilityConverter"/>
    </Window.Resources>
    
    
    <Border BorderBrush=Black
        BorderThickness="{Binding MyObject, Converter={StaticResource MyObjectBorderVisibilityConverter}">
    [...]
    

    Converters Code:

    namespace MyConverters
    {
        public class ObjectBorderVisibilityConverter: IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                Visibility v = Visibility.Hidden;
    
                List<MyObject> myObjects = value as List<MyObject>;
                foreach(Object myobject in myObjects)
                {
                       if (myobject.IsVisible)
                           v = Visibility.Visible;
                }      
                return v;
            }
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                throw new InvalidOperationException("ObjectBorderVisibilityConvertercan only be used OneWay.");        
            }
        }
    }
    

    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:

    <Window.Resources>
    <converters:ObjectBorderVisibilityConverter 
               x:Key="MyObjectBorderVisibilityConverter"/>
    </Window.Resources>
    
    
    <Border BorderBrush=Black
            BorderThickness="{Binding MyObject, Converter={StaticResource MyObjectBorderVisibilityConverter}", ConverterParameter={Binding ElementName=myGrid, BindsDirectlyToSource=True>
           <Grid x:Name="myGrid">
           [...]
    

    Revised Converter

    namespace MyConverters
    {
        public class ObjectBorderVisibilityConverter: IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                Visibility v = Visibility.Hidden;
                Grid myGrid = parameter as Grid;
                List<MyObject> myObjects = value as List<MyObject>;
                foreach (var child in LogicalTreeHelper.GetChildren(myGrid))
                {
                       if(child.GetType() == typeof(System.Windows.Controls.Label)
                          if (((Label)child).Visibility = Visibility.Visible)
                               v = Visibility.Visible;
                }     
                return v;
            }
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                throw new InvalidOperationException("ObjectBorderVisibilityConvertercan only be used OneWay.");        
            }
        }
    }
    

    I coded this all by hand so there’s prolly a bunch of errors, but I hope you get the point.

    u_u

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some legacy Pro*C code using the kind of constructs below. This kind
I have a setup similar to code below, where there can be any number
I have a bunch of occurrences of this kind of boilerplate code in my
I have this kind of table, it has many rows and each row has
Can anybody tell me how are exceptions handled in PHP? I have this code
I have this code to load a config file and read all the values
can anyone give me the help on this kind of error? Actually i have
I have a code file from the boto framework pasted below, all of the
I have this kind of node in my xml document: <parent ...> <a .../>
I have this kind of setup : Overridden BaseRunserverCommand that adds another option (--token)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.