- 浏览: 399772 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (309)
- xaml C# wpf (0)
- scala java inner clas (1)
- Tools UML Eclipse UML2 (1)
- Timer .NET Framework (1)
- perl (6)
- python function paramter (1)
- Python Docstring (1)
- Python how to compare types (1)
- Python (8)
- java (5)
- C# (76)
- C# WPF (0)
- p4 (0)
- WPF (46)
- .net (6)
- xaml (1)
- javascript (40)
- windows (10)
- scala (4)
- winform (1)
- c++ (48)
- tools (12)
- cmd (1)
- os (0)
- CI (0)
- shell (0)
- C (2)
- haskell (49)
- functional (1)
- tool (1)
- gnu (1)
- linux (1)
- kaskell (0)
- svn (0)
- wcf (3)
- android (1)
最新评论
In previous discussion wpf - RoutedCommand use example - we have see the example of how to set up the CommandBindings and how to set the Command to an UIElement and how to create the Commands objects.
We also looked the the post - wpf - RoutedEvent and EventManager.RegisterClassHandler - Routed Event Handlers (such as the class handlers and the instance handlers), you do that via the EventManager.RegisterClassHandler or through the UIElement.AddHandler methods;
you can always make comparsion between the CommandManager and the EventManager. While the following two are the CommandManager's equivalent on the RoutedEvent's AddHandlers (the RemoveHandlers is not discussed in this post).
CommandManager.AddCanExecuteHandler(UIElement, CanExecuteRoutedEventHandler);
CommandManager.AddexecutedHandler(UIElement, ExecutedRoutedEventHandler);
From what I am seeing, this is like to set up handler for the Command that is associated with the UI element (bypass the CommandBindings Stuff??)
The undetermined parts is the relation between the CommandBindings that belongs to the UIElement and the Handler that explicitly added to the UIElement through the use of CommandManager.AddExecutedHandler.
Now, there are some clear part about the relationship of the two -
- the CommandBindings always dominate the AddExecutedHandler.
Let's see the example.
namespace RoutedCommandsTest { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); CommandManager.AddExecutedHandler(this.BtnHighLightCommand, OnHighlightCommandExecuted); CommandManager.AddCanExecuteHandler(this.BtnHighLightCommand, OnHighlightCommandCanExecuted); // now what if we add the CommandBindings for this button? // if you have the following statement running after the CommandManager.AddExecutedHandler, // you will see that CommandBinding's Handler prevail this.BtnHighLightCommand.CommandBindings.Add( new CommandBinding(HighlightCommand, OnHighLightCommandBindingExecutedHandler, OnHighLightCommandBindingCanExecuteHandler)); // even though you have the AddExecutedHandler added, you will still see the handler of // CommandBindings invoked. CommandManager.AddExecutedHandler(this.BtnHighLightCommand, OnHighlightCommandExecuted); CommandManager.AddCanExecuteHandler(this.BtnHighLightCommand, OnHighlightCommandCanExecuted); } public static readonly RoutedCommand HighlightCommand = new RoutedCommand("HighlightCommand", typeof(MainWindow)); public void OnHighlightCommandExecuted(object sender, ExecutedRoutedEventArgs e) { MessageBox.Show("this is the OnHighlightCommandExecuted Handler"); } public void OnHighlightCommandCanExecuted(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = true; } public void OnHighLightCommandBindingExecutedHandler(object sender, ExecutedRoutedEventArgs e) { MessageBox.Show("This is the Command Binding's OnHighLightCommandExecute Handler"); e.Handled = false; } public void OnHighLightCommandBindingCanExecuteHandler(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = true; } } }
and below is the xaml file
<Window x:Class="RoutedCommandsTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:custom="clr-namespace:RoutedCommandsTest" Title="MainWindow" Height="350" Width="525"> <Grid> <Button x:Name="BtnHighLightCommand" Content="HightLightCommand" Command="{x:Static custom:MainWindow.HighlightCommand}" /> </Grid> </Window>
发表评论
-
wpf - example to enhance ComboBox for AutoComplete
2014-09-19 15:56 1976first let’s see an example ... -
WPF – Virtualization – VirutalizationStackPanel and ItemsPanelTemplate
2013-08-05 21:55 1410Topic: WPF – Virtualization – ... -
wpf - BehaviorBase and one use examples
2013-06-18 18:41 1311Behavior is something that we ... -
WPF - Setting foreground color of Entire window
2013-06-13 16:00 1918You might as well as I would s ... -
WPF - Enhanced TabControl - TabControlEx aka Prerendering TabControl
2013-06-13 13:12 5330As an opening word, let's che ... -
wpf - ControlTemplate and AddLogicChild/RemoveLogicalChild
2013-06-10 15:42 1185Recently I was trying to debug ... -
wpf - default implicit style
2013-05-10 10:24 794We know that if you left out ... -
wpf - Style setter on the attached property
2013-05-08 14:54 2851I believe that you are familia ... -
wpf - specify enum values in xaml
2013-05-08 11:31 3585Many a situation you find tha ... -
wpf - IG xamDataGrid bind to XmlDataProvider with Xml Island
2012-12-18 14:28 1286Sometimes you may bind to some ... -
wpf - translate winform button/mouse event to wpf events
2012-12-12 17:37 2162It is common that we sometimes ... -
wpf - Freezable and its meaning
2012-09-27 12:38 0This article is based on the di ... -
wpf - Customize the grid lines for original wpf Grid control
2012-09-27 12:01 1458The System.WIndows.Controls.Gri ... -
c# - Convert from System.Drawing.Image to System.WIndows.Media.ImageSource
2012-09-25 14:27 7417In Previous discussion, we have ... -
wpf - Get Effective DependencyProperty value on a DependencyObject
2012-08-28 19:05 1044As discussed in my previous pos ... -
wpf - Default(Theme) style and its DefaultStyleKey
2012-08-28 17:54 1387As dicsused in the subsection o ... -
wpf - Dependency Property Value Precedence
2012-08-28 18:56 882A dependency property to an Dep ... -
wpf - WPF TemplateBinding vs RelativeSource TemplatedParent
2012-08-28 14:20 3713This is a post that summarizes ... -
wpf - ICutomTypeDescriptor , PropertyDescriptor and its use in PropertyGrid
2012-08-28 14:04 3580The type ICustomTypeDe ... -
wpf - tips to convert UI controls in WPF/Silverlight/Winforms into a Bitmap
2012-08-27 17:44 975In previous discussion, we have ...
相关推荐
【标题】"WPF-JJDown-v1.234.0" 提示我们这是一个基于Windows Presentation Foundation(WPF)的应用程序,名为JJDown。版本号v1.234.0表明这是该软件的第1次重大更新,第234次次要更新或修复。这通常意味着它经历了...
gong-wpf-dragdrop, GongSolutions.WPF.DragDrop 库是WPF的拖动'n'拖放框架 简介GongSolutions.WPF.DragDrop 库是一个易于使用的拖拉'n'拖放框架。特性使用 MVVM: 拖放逻辑可以放在ViewModel中。 代码不需要放在in中...
在本项目"WPF-MaterialDesign-master.zip"中,重点在于利用**Material Design**这一设计语言来增强WPF应用的视觉效果。Material Design是Google推出的一种设计规范,其灵感来源于现实世界中的纸张和墨水,强调层次感...
【WPF】是一种Windows Presentation Foundation的简称,是微软.NET Framework的一部分,用于构建Windows桌面应用程序的UI框架。WPF提供了一套完整的图形呈现系统,包括2D和3D图形、动画、布局、文本渲染等,同时也...
Prism-Samples-Wpf-master11-15的VS2017版本实现,下载手动重新安装一下nuget包即可,方便大家学习
**WPF-Blockly** 是一个基于Windows Presentation Foundation (WPF) 的图形化编程工具,它为用户提供了构建和设计程序的直观界面。WPF作为Microsoft .NET Framework的一部分,主要用于构建桌面应用程序,它提供了...
【标题】"wpf-4_SourceCode.zip" 提供的是 WPF 4 技术的实战源代码,对应书籍 "WPF 4 Unleashed" 的配套资源。这本书由业界专家编写,深入探讨了Windows Presentation Foundation (WPF) 4 的各个方面,旨在帮助读者...
gong-wpf-dragdrop-develop.rar
GongSolutions.WPF.DragDrop 一种易于使用的WPF拖放框架。 支持.NET Framework 4.5+和.NET Core 3(3.0和3.1) 产品特点 与MVVM一起使用:拖放的逻辑可以放在ViewModel中。 无需在代码背后放置任何代码,而是将...
WPF-进阶视频教程(共113集)-028样式选择器.mp4
WPF-进阶视频教程(共113集)-036使用范围分组.mp4
WPF-进阶视频教程(共113集)-050组合到一起.mp4
WPF-进阶视频教程(共113集)-046窗口用户界面.mp4
WPF-进阶视频教程(共113集)-085块元素1.mp4
WPF-进阶视频教程(共113集)-065播放WAV音频.mp4
WPF-进阶视频教程(共113集)-113ClickOnce部署.mp4
WPF-进阶视频教程(共113集)-031模板选择器.mp4
WPF-进阶视频教程(共113集)-068媒体播放器窗口.mp4
WPF-进阶视频教程(共113集)-051Aero玻璃效果.mp4
WPF-进阶视频教程(共113集)-038创建自定义视图.mp4