我想在XAML Dictionary中的Border
上使用RoutedEvent
。 RoutedEvent
來自模板所屬的類,我如何實現這一目標?通過TemplateBinding添加RoutedEvent
ModernWindow.cs
/// <summary>
/// Gets fired when the logo is clicked.
/// </summary>
public static readonly RoutedEvent LogoClickEvent = EventManager.RegisterRoutedEvent("LogoClickRoutedEventHandler", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ModernWindow));
/// <summary>
/// The routedeventhandler for LogoClick
/// </summary>
public event RoutedEventHandler LogoClick
{
add { AddHandler(LogoClickEvent, value); }
remove { RemoveHandler(LogoClickEvent, value); }
}
/// <summary>
///
/// </summary>
protected virtual void OnLogoClick()
{
RaiseEvent(new RoutedEventArgs(LogoClickEvent, this));
}
ModernWindow.xaml
<!-- logo -->
<Border MouseLeftButtonDown="{TemplateBinding LogoClick}" Background="{DynamicResource Accent}" Width="36" Height="36" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,0,76,0">
<Image Source="{TemplateBinding Logo}" Stretch="UniformToFill" />
</Border>
THX,但究竟這就是問題所在,我需要它的主題詞典一個自定義用戶控件... – Knerd
@Knerd:請參閱有關依賴屬性的答案。 –