I have created a usercontrol (named UCDataGrid) that I want to add to my Main Window at runtime.
In MainWindow.xaml.cs:
private void GetAnotherUserControl(string sUCName)
{
var UC_Grid = new UCDataGrid();
...
// Add to 'PositioningGrid' Grid Layout
PositioningGrid.Children.Add(UC_Grid);
// Register UC_Grid Name
PositioningGrid.RegisterName(sUCName, UC_Grid);
...
}
In MainWindow.XAML [Structure]:
Grid (named “TopGrid”) -> Grid (named “PostioningGrid”)
The PositioningGrid will hold the children controls/user controls I develop which shall be added dynamically at runtime depending on Business rules.
By adding my user control in this fashion, how can I do bubbling/tunneling when I click on a checkbox in my dynamically added usercontrol?
I want to click the checkbox in my usercontrol (UCDataGrid) and run code from my MainWindow.
I have tried several ways but would like to know if there is some way to notify my MainWindow that the user has clicked on the checkbox.
Handle the
CheckBox.Checkedrouted event in the window:Or:
The
Checkedevent will bubble up from theCheckBoxto the parent window.