Reputation: 629
I need to be able to select a datagrid to display to the user depending on a button i click, i have three different datagrids. So when i select button_1 i need to show datagrid_1 and then datagrid_2 and datagrid_3 need to be hidden in the user interface.
In windows forms you could simply say:
datagrid_1.Visible = false; / datagrid_1.Visible = true;
In WPF this doesn't work, so i am wondering how i would go about hiding datagrids on button click. Using datagrid_1.IsVisible does not work either.
This is how i would have normally done it in windows forms:
protected void btn1_Click(object sender, EventArgs e)
{
datagrid_1.Visible = true;
datagrid_2.Visible = false;
datagrid_3.Visible = false;
lblPageHeader.Text = "datagrid_1 is selected";
}
My only other idea was to put these datagrids in their own user controls and then load the user control based on the button click but surely there is a quicker way to achieve this? So what would be the best way to achieve similar results in WPF?
Upvotes: 0
Views: 575
Reputation: 9439
You can try Visibility
property in WPF
private void btn1_Click(object sender, EventArgs e)
{
datagrid_1.Visibility = Visibility.Visible;
datagrid_2.Visibility = Visibility.Collapsed;
datagrid_3.Visibility = Visibility.Collapsed;
lblPageHeader.Text = "datagrid_1 is selected";
}
Upvotes: 1
Reputation: 59
In WPF you can use databindings, to achieve the same.
Here's a link to a short tutorial about databinding: http://www.wpftutorial.net/DataBindingOverview.html
Upvotes: 0