2
我已经为它创建了资源字典和代码文件。 在XAML我已经定义命令绑定,并添加已执行处理程序:执行命令不在后面的资源字典代码中触发
<Button Grid.Row="2" Width="100" >
<CommandBinding Command="Search" Executed="CommandBinding_Executed" />
</Button>
这里是后面的代码:
partial class StyleResources : ResourceDictionary {
public StyleResources() {
InitializeComponent();
}
private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e) {
//this is never executed
}
}
我不知道为什么不执行命令按钮被点击的时候,而且,为什么当我没有将CanExecute设置为true时启用按钮。我也尝试将其设置为true,但CanExecute事件并没有触发。 这里是我如何使用资源字典:
public partial class MyWindow : Window {
public MyWindow() {
InitializeComponent();
Uri uri = new Uri("/WPFLibs;component/Resources/StyleResources.xaml", UriKind.Relative);
ResourceDictionary Dict = Application.LoadComponent(uri) as ResourceDictionary;
this.Style = Dict["WindowTemplate"] as Style;
}
}
谢谢的作品! – Vale 2011-04-12 09:35:23