{"id":1615,"date":"2023-06-08T11:20:10","date_gmt":"2023-06-08T03:20:10","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=1615"},"modified":"2023-06-08T11:20:10","modified_gmt":"2023-06-08T03:20:10","slug":"wpf%e5%a6%82%e4%bd%95%e9%81%bf%e5%85%8d%e5%91%bd%e4%bb%a4%e5%90%91%e4%b8%8a%e4%bc%a0%e9%80%92%e5%bd%b1%e5%93%8d%e6%80%a7%e8%83%bd","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2023\/06\/08\/wpf%e5%a6%82%e4%bd%95%e9%81%bf%e5%85%8d%e5%91%bd%e4%bb%a4%e5%90%91%e4%b8%8a%e4%bc%a0%e9%80%92%e5%bd%b1%e5%93%8d%e6%80%a7%e8%83%bd\/","title":{"rendered":"WPF\u5982\u4f55\u907f\u514d\u547d\u4ee4\u5411\u4e0a\u4f20\u9012\u5f71\u54cd\u6027\u80fd"},"content":{"rendered":"\n<p>\u5728WPF\u4e2d\uff0c\u547d\u4ee4\u7684\u8def\u7531\u673a\u5236\u53ef\u4ee5\u5bfc\u81f4\u547d\u4ee4\u5411\u4e0a\u4f20\u9012\uff0c\u4ece\u800c\u5f71\u54cd\u6027\u80fd\u3002\u5982\u679c\u4f60\u5e0c\u671b\u907f\u514d\u547d\u4ee4\u5411\u4e0a\u4f20\u9012\u5e76\u63d0\u9ad8\u6027\u80fd\uff0c\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>\u53d6\u6d88\u547d\u4ee4\u7684\u8def\u7531<\/strong>\uff1a\u53ef\u4ee5\u5728\u547d\u4ee4\u5904\u7406\u7a0b\u5e8f\u4e2d\u624b\u52a8\u53d6\u6d88\u547d\u4ee4\u7684\u8def\u7531\uff0c\u4ee5\u963b\u6b62\u547d\u4ee4\u5411\u4e0a\u4f20\u9012\u3002\u5728\u5904\u7406\u547d\u4ee4\u65f6\uff0c\u5224\u65ad\u662f\u5426\u5df2\u7ecf\u8fbe\u5230\u4e86\u547d\u4ee4\u7684\u6700\u7ec8\u5904\u7406\u76ee\u6807\uff0c\u5982\u679c\u662f\uff0c\u5219\u53d6\u6d88\u547d\u4ee4\u7684\u8def\u7531\u3002\u53d6\u6d88\u547d\u4ee4\u7684\u8def\u7531\u53ef\u4ee5\u4f7f\u7528<code>e.Handled = true;<\/code>\u8bed\u53e5\u5b9e\u73b0\uff0c\u5176\u4e2d<code>e<\/code>\u662f<code>ExecutedRoutedEventArgs<\/code>\u53c2\u6570\u3002csharpCopy code<code>private void CommandHandler(object sender, ExecutedRoutedEventArgs e) { \/\/ \u6267\u884c\u547d\u4ee4\u5904\u7406\u903b\u8f91 \/\/ \u53d6\u6d88\u547d\u4ee4\u7684\u8def\u7531 e.Handled = true; } <\/code>\u8fd9\u6837\u505a\u53ef\u4ee5\u963b\u6b62\u547d\u4ee4\u7ee7\u7eed\u5411\u4e0a\u4f20\u9012\uff0c\u4ece\u800c\u51cf\u5c11\u989d\u5916\u7684\u547d\u4ee4\u5904\u7406\u548c\u4e8b\u4ef6\u5192\u6ce1\u3002<\/li><li><strong>\u4f18\u5316\u547d\u4ee4\u7ed1\u5b9a<\/strong>\uff1a\u5982\u679c\u4f60\u5728\u591a\u4e2a\u5143\u7d20\u4e0a\u4f7f\u7528\u76f8\u540c\u7684\u547d\u4ee4\u7ed1\u5b9a\uff0c\u53ef\u4ee5\u8003\u8651\u5c06\u547d\u4ee4\u7ed1\u5b9a\u63d0\u5347\u5230\u5171\u4eab\u7684\u7236\u7ea7\u5143\u7d20\u4e0a\u3002\u8fd9\u6837\u53ef\u4ee5\u51cf\u5c11\u547d\u4ee4\u7ed1\u5b9a\u7684\u6570\u91cf\uff0c\u4ece\u800c\u964d\u4f4e\u547d\u4ee4\u5411\u4e0a\u4f20\u9012\u7684\u6b21\u6570\u3002<\/li><li><strong>\u907f\u514d\u5197\u4f59\u7684\u547d\u4ee4\u5904\u7406<\/strong>\uff1a\u5728\u547d\u4ee4\u5904\u7406\u7a0b\u5e8f\u4e2d\uff0c\u786e\u4fdd\u53ea\u5904\u7406\u4e0e\u5f53\u524d\u5143\u7d20\u76f8\u5173\u7684\u547d\u4ee4\uff0c\u907f\u514d\u5904\u7406\u4e0e\u5f53\u524d\u5143\u7d20\u65e0\u5173\u7684\u547d\u4ee4\u3002\u53ef\u4ee5\u4f7f\u7528<code>CommandParameter<\/code>\u5c5e\u6027\u6216\u8005\u5728\u547d\u4ee4\u5904\u7406\u7a0b\u5e8f\u4e2d\u68c0\u67e5\u547d\u4ee4\u7684\u6e90\u5143\u7d20\u6765\u8fdb\u884c\u6761\u4ef6\u5224\u65ad\u3002csharpCopy code<code>private void CommandHandler(object sender, ExecutedRoutedEventArgs e) { if (e.Source == this) { \/\/ \u53ea\u5904\u7406\u4e0e\u5f53\u524d\u5143\u7d20\u76f8\u5173\u7684\u547d\u4ee4 } }<\/code><\/li><li><strong>\u4f7f\u7528\u5f02\u6b65\u547d\u4ee4\u5904\u7406<\/strong>\uff1a\u5982\u679c\u547d\u4ee4\u5904\u7406\u903b\u8f91\u6d89\u53ca\u8017\u65f6\u7684\u64cd\u4f5c\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u5f02\u6b65\u547d\u4ee4\u5904\u7406\u3002\u8fd9\u6837\u53ef\u4ee5\u5c06\u547d\u4ee4\u5904\u7406\u8fc7\u7a0b\u653e\u5728\u540e\u53f0\u7ebf\u7a0b\u4e2d\u8fdb\u884c\uff0c\u907f\u514d\u963b\u585e\u4e3b\u7ebf\u7a0b\u548cUI\u54cd\u5e94\u3002csharpCopy code<code>private async void CommandHandler(object sender, ExecutedRoutedEventArgs e) { \/\/ \u5f02\u6b65\u6267\u884c\u547d\u4ee4\u5904\u7406\u903b\u8f91 await Task.Run(() =&gt; { \/\/ \u6267\u884c\u8017\u65f6\u7684\u64cd\u4f5c }); }<\/code><\/li><\/ol>\n\n\n\n<p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u907f\u514d\u547d\u4ee4\u5411\u4e0a\u4f20\u9012\u5bf9\u6027\u80fd\u7684\u5f71\u54cd\uff0c\u63d0\u9ad8WPF\u5e94\u7528\u7a0b\u5e8f\u7684\u54cd\u5e94\u901f\u5ea6\u548c\u6548\u7387\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728WPF\u4e2d\uff0c\u547d\u4ee4\u7684\u8def\u7531\u673a\u5236\u53ef\u4ee5\u5bfc&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1615","post","type-post","status-publish","format-standard","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=1615"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1615\/revisions"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=1615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=1615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=1615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}