0

I want to create simple WPF application with toolbar and one workspace with parameter text boxes. In the main window i have a grid like this:

In the ToolBarGrid i want to put a user control with two buttons ToolBarUC. When you click the button1, in the ParametersGrid appears UC1 and when you click the button2, in the ParametersGrid appears UC2. Now i have created the MainWindow grids and i have the created 3 user controls(ToolBarUC, UC1, UC2). I have created two events in the ToolBarUC.cs for the two buttons btn1_Click and btn2_click and i put the ToolBarUC into the ToolBarGrid.

The question is what code to put in btn1_clik and btn2_click so UC1 and UC2 appears in ParametersGrid

  • *"how can i connect them with code"* - with what code? – Sinatr Mar 13 '17 at 15:05
  • The question is what code to put in btn1_clik and btn2_click so UC1 and UC2 appears in ParametersGrid –  Mar 13 '17 at 15:12
  • Are you asking [how to set grid column/row programmatically](http://stackoverflow.com/q/3745594/1997232) ? – Sinatr Mar 13 '17 at 15:15
  • in the MainWindow.cs i write this code: var ToolBarItem = new ToolBarUC(); ToolbarGrid.Children.Add(ToolBarItem); and ToolBarUC appears in tool bar grid. But when i want to write ParametersGrid.Children.Add(UC1item) inToolBarUS.cs i cannot access the ParametersGrid –  Mar 13 '17 at 15:20
  • You can make this control (grid?) exposed as `public` property (dependency property if you want binding, but this is more [complicated](http://stackoverflow.com/q/9986698/1997232)). It should have `x:Name="tralala"` and property which basically return instance: `public Grid ParametersGrid => tralala;`, then you will be able to use `ParametersGrid` property outside of user control to access element and its instance members. – Sinatr Mar 13 '17 at 15:30
  • How can I make a Grid to be public –  Mar 14 '17 at 19:33
  • [How make element public](http://stackoverflow.com/q/2093855/1997232). – Sinatr Mar 15 '17 at 07:59

1 Answers1

0

The code in your button click handlers need to set the Visibility property on the UC controls. So one button will hide one and show the other and the other button will do the reverse.

AQuirky
  • 4,691
  • 2
  • 32
  • 51