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 9183965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:55:51+00:00 2026-06-17T18:55:51+00:00

I have userControl with a GridView of GridViews (A GridView who’s data context is

  • 0

I have userControl with a GridView of GridViews (A GridView who’s data context is another GridView) so when i set the itemssource to a collection of collection i can see a hierarchical view.

eg:

Parent Collection is List<ClassRoom> and the parent Collection has a Property List<Student>

The above Classes are defined and i can’t modify the class(as we consider it is in Model Layer) for the use of my UserControl.

Because i am developing a UserControl i have defined a Property called bool ShowChildItems.

if ShowChildItems is set to false i want the childGridView to be Collapsed.

How can i bind the property of the user control to childGridView.Visisbility.
(ShowChildItems property value may change at runtime,depending on the instance of the UserControl)

  • 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-17T18:55:52+00:00Added an answer on June 17, 2026 at 6:55 pm

    To have a ShowChildItems property in your UserControl to manage the Visibility of your child GridView you first need to make it a DependencyProperty:

    public static readonly DependencyProperty ShowChildItemsProperty =
        DependencyProperty.Register("showChildItems", typeof (bool), typeof (MyUserControl), new PropertyMetadata(true));
    
    public bool ShowChildItems
    {
        get { return (bool) GetValue(ShowChildItemsProperty); }
        set { SetValue(ShowChildItemsProperty, value); }
    }
    

    Inside the UserControl you will bind the GridView Visibility to this property by using the ElementName syntax – this way it doesn’t matter what the GridView DataContext is bound to:

    <GridView Visibility="{Binding ShowChildItems, ElementName=ControlRoot, Converter={StaticResource VisibilityConverter}}" ItemsSource="{Binding ChildItems}">
    

    For this to work you need to set the name to UserControl‘s root node (I’ve omitted the rest of the attributes):

    <UserControl
        x:Name="ControlRoot">
    

    I’ve also used a converter to bind a bool property to Visibility:

    <UserControl.Resources>
        <local:BoolToVisibilityConverter x:Key="VisibilityConverter" />
    </UserControl.Resources>
    

    This is its code:

    public class BoolToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (!(value is bool)) return Visibility.Collapsed;
    
            return (bool) value ? Visibility.Visible : Visibility.Collapsed;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }
    

    I hope this is what you were asking for. I’m not quite sure based on your question.

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

Sidebar

Related Questions

I have a usercontrol that can be used in for example a gridview itemtemplate,
I am making Winforms application. I have put gridview in usercontrol. Which is another
I have ModalPopupExtender that contains a UserControl that basically consists of a GridView and
I have a gridview which is in a usercontrol on a page. The gridview
I have created a gridview for populating data, and some user control (TextBox) to
I have a web project in C#/asp.net. I have a UserControl with a GridView
I have a gridview that has a usercontrol in a template column on each
I have a gridview and usercontrol on the page, I want to alter gridview
I have user control with a gridview, but for some reason I can't use
I'm sure I'm missing something obvious here. I have a about twenty data-bound GridViews,

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.