2017-09-15 7 views
0

런타임시 주 윈도우에 추가하려는 usercontrol (UCDataGrid)을 만들었습니다. MainWindow.xaml.cs를WPF C# UC에서 패널로 거품/터널을 동적으로 패널하는 사용자 컨트롤을 추가하는 방법

에서

:

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); 

    ... 
} 

에서 MainWindow.XAML [구조]

Grid (named “TopGrid”) -> Grid (named “PostioningGrid”) 

PositioningGrid 동적으로 추가한다 I 개발 아이들 제어/사용자 제어를 보유 할 비즈니스 규칙에 따라 런타임에.

내 사용자 정의 컨트롤을이 방식으로 추가하면 동적으로 추가 된 usercontrol에서 체크 상자를 클릭하면 버블 링/터널링을 어떻게 할 수 있습니까?

내 usercontrol (UCDataGrid)의 확인란을 클릭하고 내 MainWindow에서 코드를 실행하고 싶습니다.

여러 가지 방법을 시도했지만 사용자가 체크 박스를 클릭 한 것을 내 MainWindow에 알리는 방법이 있는지 알고 싶습니다.

답변

0

이 창에서 CheckBox.Checked 라우트 된 이벤트를 처리 :

<Window x:Class="WpfApplication1.Window1" 
     ... 
     Title="Window7" Height="300" Width="300" CheckBox.Checked="Window_Checked"> 

또는를 :

this.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(Window_Checked)); 

Checked 이벤트 것까지 부모 창에 CheckBox에서 거품.