{"id":5179,"date":"2014-11-26T22:42:28","date_gmt":"2014-11-26T13:42:28","guid":{"rendered":"http:\/\/umezawa.dyndns.info\/wordpress\/?p=5179"},"modified":"2014-11-26T22:42:49","modified_gmt":"2014-11-26T13:42:49","slug":"wpf-%e3%81%a7%e3%80%81%e3%83%93%e3%83%a5%e3%83%bc%e3%82%92%e6%a7%8b%e7%af%89%e3%81%97%e3%81%9f%e7%9b%b4%e5%be%8c%e3%81%ab%e3%82%b3%e3%83%b3%e3%83%86%e3%82%ad%e3%82%b9%e3%83%88%e3%83%a1%e3%83%8b","status":"publish","type":"post","link":"http:\/\/umezawa.dyndns.info\/wordpress\/?p=5179","title":{"rendered":"WPF \u3067\u3001\u30d3\u30e5\u30fc\u3092\u69cb\u7bc9\u3057\u305f\u76f4\u5f8c\u306b\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30e1\u30cb\u30e5\u30fc\u3092\u8868\u793a\u3055\u305b\u308b\u3068\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u30b3\u30de\u30f3\u30c9\u306e CanExecute \u304c\u547c\u3070\u308c\u306a\u3044\uff08\u672a\u89e3\u6c7a\uff09 (Windows\/.NET\/WPF)"},"content":{"rendered":"<p>.NET Framework 4.5 \u3092\u4f7f\u3044\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30a6\u30a3\u30f3\u30c9\u30a6\u3092\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n<p><!--more--><\/p>\n<blockquote>\n<pre>&lt;Window x:Class=\"ListViewContextMenuTest.MainWindow\"\r\n        xmlns=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation\"\r\n        xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\"\r\n        Title=\"MainWindow\" Height=\"350\" Width=\"525\">\r\n    &lt;StackPanel>\r\n        &lt;TextBlock Text=\"ABCDEFG&amp;#x0a;HIJKLMN\">\r\n            &lt;TextBlock.ContextMenu>\r\n                &lt;ContextMenu>\r\n                    &lt;MenuItem Header=\"RoutedCommand\" Command=\"ApplicationCommands.Help\"\/>\r\n                    &lt;MenuItem Header=\"PropertyCommand\" Command=\"{Binding PropertyCommand}\"\/>\r\n                &lt;\/ContextMenu>\r\n            &lt;\/TextBlock.ContextMenu>\r\n        &lt;\/TextBlock>\r\n        &lt;Button Content=\"XYZ\"\/>\r\n    &lt;\/StackPanel>\r\n&lt;\/Window><\/pre>\n<\/blockquote>\n<blockquote>\n<pre>namespace ListViewContextMenuTest\r\n{\r\n    public partial class MainWindow : Window\r\n    {\r\n        public MainWindow()\r\n        {\r\n            InitializeComponent();\r\n            DataContext = new MainViewModel();\r\n\r\n            CommandBindings.Add(new CommandBinding(ApplicationCommands.Help, Command_Executed, Command_CanExecute));\r\n        }\r\n\r\n        private void Command_Executed(object sender, ExecutedRoutedEventArgs e)\r\n        {\r\n        }\r\n\r\n        private void Command_CanExecute(object sender, CanExecuteRoutedEventArgs e)\r\n        {\r\n            e.CanExecute = true;\r\n        }\r\n    }\r\n\r\n    public class MainViewModel\r\n    {\r\n        public class PropertyCommandClass : ICommand\r\n        {\r\n            public event EventHandler CanExecuteChanged;\r\n\r\n            public void Execute(object parameter)\r\n            {\r\n            }\r\n\r\n            public bool CanExecute(object parameter)\r\n            {\r\n                return true;\r\n            }\r\n        }\r\n\r\n        public PropertyCommandClass PropertyCommand { get; private set; }\r\n\r\n        public MainViewModel()\r\n        {\r\n            PropertyCommand = new PropertyCommandClass();\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<\/blockquote>\n<p>\u5206\u96e2\u30b3\u30fc\u30c9\u306f\u5358\u306b CanExecute \u306b\u5fdc\u7b54\u3057\u3066\u3044\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u3092\u5b9f\u884c\u3057\u3066<strong>\u3059\u3050\u306b<\/strong> TextBlock \u306e\u4e0a\u3067\u53f3\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u3001\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u30b3\u30de\u30f3\u30c9\u3092\u8a2d\u5b9a\u3057\u305f\u30e1\u30cb\u30e5\u30fc\u30a2\u30a4\u30c6\u30e0\u306f enabled \u306b\u306a\u3089\u305a\u3001\u30d3\u30e5\u30fc\u30e2\u30c7\u30eb\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u3042\u308b\u30b3\u30de\u30f3\u30c9\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8a2d\u5b9a\u3057\u305f\u30e1\u30cb\u30e5\u30fc\u30a2\u30a4\u30c6\u30e0\u3060\u3051\u304c enabled \u306b\u306a\u308a\u307e\u3059\u3002Console.WriteLine \u306a\u3069\u3067\u30ed\u30b0\u3092\u51fa\u3059\u3088\u3046\u306b\u3057\u3066\u307f\u308b\u3068\u3001\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u30b3\u30de\u30f3\u30c9\u306e\u65b9\u306e CanExecute (Command_CanExecute) \u306f\u547c\u3070\u308c\u3066\u3044\u306a\u3044\u3053\u3068\u304c\u5206\u304b\u308a\u307e\u3059\u3002\u4f55\u5ea6\u53f3\u30af\u30ea\u30c3\u30af\u3057\u3066\u3082\u540c\u3058\u3067\u3059\u3002<\/p>\n<p>\u4e00\u65b9\u3001\u4e00\u5ea6\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u3066\u304b\u3089\u307e\u305f TextBlock \u306e\u4e0a\u3067\u53f3\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u3001\u4eca\u5ea6\u306f CanExecute \u304c\u547c\u3070\u308c\u3001\u3061\u3083\u3093\u3068\u30e1\u30cb\u30e5\u30fc\u30a2\u30a4\u30c6\u30e0\u304c enabled \u306b\u306a\u308a\u307e\u3059\u3002\u4e00\u65e6\u305d\u3046\u306a\u308b\u3068\u305a\u3063\u3068 CanExecute \u306e\u5fdc\u7b54\u306b\u5f93\u3046\u72b6\u614b\u306e\u307e\u307e\u3067\u3059\u3002\uff08\u4e0a\u306e\u30b3\u30fc\u30c9\u3067\u306f\u5e38\u306b true \u3067\u3059\u304c\uff09<\/p>\n<p>\u8a66\u3057\u305f\u3053\u3068\uff08\u5168\u90e8\u52b9\u679c\u306a\u3057\uff09<\/p>\n<ul>\n<li>MainWindow \u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306e\u6700\u5f8c\u306b CommandManager.InvalidateRequerySuggested \u3092\u547c\u3076<\/li>\n<li>TextBlock \u306e OnContextMenuOpening \u30a4\u30d9\u30f3\u30c8\u304c\u767a\u751f\u3057\u305f\u6642\u306b CommandManager.InvalidateRequerySuggested \u3092\u547c\u3076<\/li>\n<li>CommandBindings.Add \u3092\u4f7f\u308f\u305a\u306b XAML \u3067\u8a18\u8ff0\u3059\u308b<\/li>\n<\/ul>\n<p>\u3053\u3061\u3089\u3068\u3057\u3066\u306f\u6700\u521d\u304b\u3089 CanExecute \u304c\u547c\u3070\u308c\u308b\u3053\u3068\u3092\u671f\u5f85\u3057\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u4f55\u304c\u3044\u3051\u306a\u3044\u3093\u3067\u3057\u3087\u3046\u2026<\/p>\n","protected":false},"excerpt":{"rendered":"<p>.NET Framework 4.5 \u3092\u4f7f\u3044\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30a6\u30a3\u30f3\u30c9\u30a6\u3092\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"class_list":["post-5179","post","type-post","status-publish","format-standard","hentry","category-technology"],"_links":{"self":[{"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/5179","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5179"}],"version-history":[{"count":6,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/5179\/revisions"}],"predecessor-version":[{"id":5185,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/5179\/revisions\/5185"}],"wp:attachment":[{"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5179"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}