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

  • Home
  • SEARCH
  • 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 7612907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:02:11+00:00 2026-05-31T02:02:11+00:00

I set my DataGrid to collapse when there are no items <DataGrid Name=dataGrid Visibility={Binding

  • 0

I set my DataGrid to collapse when there are no items

<DataGrid Name="dataGrid"
          Visibility="{Binding HasItems,
                       ElementName=dataGrid,
                       Converter={StaticResource BooleanToVisibilityConverter}}">
</DataGrid>

The problem is, I would like it to appear on design mode. How to do it? Should I create fake data?

I tried

    private void UserControl_Loaded(object sender, RoutedEventArgs e)
    {
        if (DesignerProperties.GetIsInDesignMode(this))
        {
            this.dataGrid.ItemsSource = new List<Table> { new Table() };
        }
    }

but it didn’t work

  • 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-05-31T02:02:12+00:00Added an answer on May 31, 2026 at 2:02 am

    If I understand what you are trying to do, this works well for me:

    <Window x:Class="WPFScratch.MainWindow"
        xmlns:local="clr-namespace:WPFScratch"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        mc:Ignorable="d"
        d:DesignHeight="300"  
        d:DesignWidth="592"  
        d:DataContext="{d:DesignInstance local:MyDesignTimeViewModel, IsDesignTimeCreatable=True}"
        Title="MainWindow" SizeToContent="WidthAndHeight">
    <Window.Resources>
        <local:BoolToVisibilityConverter
         x:Key="BoolToHiddenConverter"
         TrueValue="Visible" FalseValue="Hidden" />        
    </Window.Resources>
    <DockPanel>       
        <DataGrid Name="dataGrid" ItemsSource="{Binding People}"
          Visibility="{Binding HasItems,
                       ElementName=dataGrid,
                       Converter={StaticResource BoolToHiddenConverter}}" AutoGenerateColumns="True">
    
        </DataGrid>
    </DockPanel>
    

    public class MyDesignTimeViewModel
    {
        public ObservableCollection<Person> People
        {
            get 
            { 
                return new ObservableCollection<Person> { 
                                                            new Person 
                                                                { 
                                                                    Name = "Simon" 
                                                                },
                                                            new Person 
                                                                { 
                                                                    Name = "Jack" 
                                                                } 
                                                        }; 
            }
        }
    }
    
    public class Person
    {
        public string Name { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I bind the datagrid visibility using MVVM so that if there is
I would like simply set the selectedItem of the Datagrid to the incoming loadingRow.
I have created WPF MVVM application, and set WPFToolkit DataGrid binding to DataTable so
I would like to set up a datagrid so that whenever an item is
How would you go about binding a WPF datagrid that needs to display data
I have a DataGrid and I set the DataProvider to my data. When my
How can I set ID to TabelRows generated by DataGrid/DataList ? I want to
I have a data set whose elements are displayed as rows in a DataGrid.
I've a custom itemRenderer for my datagrid. To set the actual data I use
I have a DataGrid who's RowDetails is set to show when selected (RowDetailsVisibilityMode=VisibleWhenSelected). Now

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.