{"id":890,"date":"2021-09-16T20:13:44","date_gmt":"2021-09-16T12:13:44","guid":{"rendered":"http:\/\/www.wayln.com\/?p=890"},"modified":"2021-09-16T20:13:44","modified_gmt":"2021-09-16T12:13:44","slug":"%e7%90%86%e8%a7%a3%e8%b7%af%e7%94%b1%e4%ba%8b%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/www.wayln.com\/?p=890","title":{"rendered":"\u7406\u89e3\u8def\u7531\u4e8b\u4ef6"},"content":{"rendered":"<div id=\"toc_container\" class=\"toc_transparent no_bullets\"><p class=\"toc_title\">Contents<\/p><ul class=\"toc_list\"><li><a href=\"#i\"><span class=\"toc_number toc_depth_1\">1<\/span> \u5b9a\u4e49\u3001\u6ce8\u518c\u548c\u5c01\u88c5\u8def\u7531\u4e8b\u4ef6<\/a><\/li><li><a href=\"#i-2\"><span class=\"toc_number toc_depth_1\">2<\/span> \u5171\u4eab\u8def\u7531\u4e8b\u4ef6<\/a><\/li><li><a href=\"#i-3\"><span class=\"toc_number toc_depth_1\">3<\/span> \u5f15\u53d1\u8def\u7531\u4e8b\u4ef6<\/a><\/li><\/ul><\/div>\n<p>\u8def\u7531\u4e8b\u4ef6\u5177\u6709\u66f4\u5f3a\u4f20\u64ad\u80fd\u529b\u2014\u2014\u53ef\u5728\u5143\u7d20\u6811\u5411\u4e0a\u5192\u6ce1\u548c\u4e61\u4e0b\u96a7\u9053\u4f20\u64ad\uff0c\u5e76\u4e14\u6cbf\u7740\u4f20\u64ad\u8def\u5f84\u88ab\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\u5904\u7406\u3002<br \/>\n\u5229\u7528\u4e8b\u4ef6\u8def\u7531\uff0c\u6765\u81ea\u5de5\u5177\u680f\u6309\u94ae\u7684\u5355\u51fb\u4e8b\u4ef6\u53ef\u5728\u88ab\u4ee3\u7801\u5904\u7406\u4e4b\u524d\u4e0a\u4f20\u5230\u5de5\u5177\u680f\uff0c\u7136\u540e\u4e0a\u4f20\u5230\u5305\u542b\u5de5\u5177\u680f\u7684\u7a97\u53e3\u3002<\/p>\n<h1><span id=\"i\">\u5b9a\u4e49\u3001\u6ce8\u518c\u548c\u5c01\u88c5\u8def\u7531\u4e8b\u4ef6<\/span><\/h1>\n<p>\u548c\u4f9d\u8d56\u9879\u5c5e\u6027\u4e00\u6837\uff0c\u8def\u7531\u4e8b\u4ef6\u7531\u53ea\u8bfb\u7684\u9759\u6001\u5b57\u6bb5\u8868\u793a\u3002\u5728\u9759\u6001\u6784\u9020\u51fd\u6570\u4e2d\u6ce8\u518c\uff0c\u5e76\u901a\u8fc7\u6807\u51c6\u7684.net\u4e8b\u4ef6\u5b9a\u4e49\u8fdb\u884c\u5c01\u88c5<\/p>\n<pre><code class=\"language-CSharp line-numbers\">public abstract class ButtonBase:ContentControl,...\n{\n    public static readonly RouteEvent ClientEvent;\n    static ButtonBase()\n    {\n        ButtonBase.ClientEvent=EventManager.RegisterRouteEvent(\"Click\",RoutingStategy.Bubble,typeof(RouteEventHandler),typepof(ButtonBase));\n        ...\n    }\n    public event RouteEventHandler Click\n    {\n        add\n        {\n            base.AddHandler(Button.ClickEvent,value);\n        }\n        remove\n        {\n            base.RemoveHandler(Button.ClickEvent,value);\n        }\n    }\n}\n<\/code><\/pre>\n<h1><span id=\"i-2\">\u5171\u4eab\u8def\u7531\u4e8b\u4ef6<\/span><\/h1>\n<p>\u53ef\u4ee5\u5728\u7c7b\u4e4b\u95f4\u5171\u4eab\u8def\u7531\u4e8b\u4ef6\u7684\u5b9a\u4e49\uff0c<\/p>\n<pre><code class=\"language-CSharp line-numbers\">UIElement.MouseUpEvent=Mouse.MouseUpEvent.AddOwner(typeof(UIElement));\n<\/code><\/pre>\n<h1><span id=\"i-3\">\u5f15\u53d1\u8def\u7531\u4e8b\u4ef6<\/span><\/h1>\n<p>\u4e0d\u662f\u901a\u8fc7\u4f20\u7edf\u7684.Net\u4e8b\u4ef6\u5c01\u88c5\u5668\u5f15\u53d1\u7684\uff0c\u800c\u662f\u4f7f\u7528RaiseEvent()\u65b9\u6cd5\u5f15\u53d1\u4e8b\u4ef6\uff0c\u6240\u6709\u5143\u7d20\u90fd\u4eceUIElement\u7c7b\u7ee7\u627f\u4e86\u8be5\u65b9\u6cd5\u3002<\/p>\n<pre><code class=\"language-CSharp line-numbers\">RouteEventArgs e=new RouteEventArgs(ButtonBase.ClickEvent,this);\nbase.RaiseEvent(e);\n<\/code><\/pre>\n<p>RaiseEvent()\u65b9\u6cd5\u8d1f\u8d23\u4e3a\u6bcf\u4e2a\u5df2\u7ecf\u901a\u8fc7AddHandler\uff08\uff09\u65b9\u6cd5\u6ce8\u518c\u7684\u8c03\u7528\u7a0b\u5e8f\u5f15\u53d1\u4e8b\u4ef6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Contents1 \u5b9a\u4e49\u3001\u6ce8\u518c\u548c\u5c01\u88c5\u8def\u7531\u4e8b\u4ef62 \u5171\u4eab\u8def\u7531\u4e8b\u4ef63 \u5f15\u53d1\u8def\u7531\u4e8b\u4ef6 \u8def\u7531\u4e8b\u4ef6\u5177\u6709\u66f4\u5f3a\u4f20\u64ad\u80fd\u529b\u2014\u2014\u53ef\u5728 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,35,36,2],"tags":[],"class_list":["post-890","post","type-post","status-publish","format-standard","hentry","category-c","category-wpf","category-2"],"_links":{"self":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=890"}],"version-history":[{"count":1,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/890\/revisions"}],"predecessor-version":[{"id":891,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/890\/revisions\/891"}],"wp:attachment":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}