【发布时间】:2014-03-09 15:13:48
【问题描述】:
我有这个 xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:l="clr-namespace:My.Windows"
>
<ObjectDataProvider x:Key="TitledWindow_Test" MethodName="Test" ObjectInstance={x:Type l:TitledWindow}">
<ControlTemplate x:Key="TitledWindowControlTemplateKey" x:Name="PART_ControlTemplate" TargetType="{x:Type l:TitledWindow}"
<Rectangle>
<Rectangle.Style>
<EventSetter Event="Mouse.MouseEnter" Handler="{StaticResource TitledWindow_Test}">
</Rectangle.Style>
</Rectangle>
</ControlTemplate>
</ResourceDictionary>
还有我的 c# 代码:
namespace My.Windows
{
public partial class TitledWindow : Window
{
public void Test()
{
MessageBox.Show("Test");
}
}
}
问题是我收到以下错误:
错误 1
'ResourceDictionary' 根元素需要 x:Class 属性来支持事件
XAML 文件中的处理程序。删除 MouseEnter 事件的事件处理程序,
或向根元素添加 x:Class 属性。
【问题讨论】:
-
你想做什么??
-
我想通过 XAML 将多个处理程序添加到唯一事件
-
@Jovan - 你不能在资源字典后面的代码中使用方法吗?我认为您不能像这样将 ObjectDataProvider 挂钩到 RoutedEvent 以及委托具有不同签名的地方。
-
那么我怎样才能使用这种方法或任何方法..?
-
检查我的答案是否在 ResourceDictionary 中有代码。
标签: c# wpf xaml events binding