2015-02-11 40 views
0

我一直无法找到答案。我有一系列的用户控件,每个都创建一个或多个用户控件子项。系列中的最后一个用户控件创建使用非托管代码的自定义控件。如何将一个事件处理程序从一个customcontrol附加到它的父级usercontrol关闭事件?

我需要让自定义控件知道用户在单击右上角的“X”时关闭其父级用户控制窗口。这样才能正确处理非托管代码。

基本XAML是:

<UserControl x:Class="Nova5.UI.Views.Ink.InkEditorView" 
     <!--DataContext in InkEditorViewModel.cs--> 
     <wc:CustomInkCanvas x:Name="myInkCanvas" 
          Vocabulary="{Binding Vocabulary, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" 
          Text="{Binding Text, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" 
          WordPad="{Binding WordPad, UpdateSourceTrigger=PropertyChanged, Mode=OneWayToSource}" 
          CloseCharacterPads ="{Binding CloseCharacterPads}"/> 
</UserControl> 

假设用户控件本身可以知道从其父用户控件结束活动,我怎么能附上自定义控件WC的方法:CustomInkCanvas到闭幕其父用户控件的事件?

任何帮助,非常感谢。谢谢。

回答

0

不是问题的答案我真的很希望,但这种放置在customInkCanvas构造函数时的工作原理:

Unloaded += new RoutedEventHandler(CustomInkCanvas_Unloaded); 

更好的想法?

相关问题