{"id":1605,"date":"2023-06-08T10:10:16","date_gmt":"2023-06-08T02:10:16","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=1605"},"modified":"2023-06-08T10:10:16","modified_gmt":"2023-06-08T02:10:16","slug":"wpf%e9%80%bb%e8%be%91%e6%a0%91%e5%92%8c%e8%a7%86%e8%a7%89%e6%a0%91","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2023\/06\/08\/wpf%e9%80%bb%e8%be%91%e6%a0%91%e5%92%8c%e8%a7%86%e8%a7%89%e6%a0%91\/","title":{"rendered":"WPF\u903b\u8f91\u6811\u548c\u89c6\u89c9\u6811"},"content":{"rendered":"\n<p><br>\u5728WPF\u4e2d\uff0c\u903b\u8f91\u6811\uff08Logical Tree\uff09\u548c\u89c6\u89c9\u6811\uff08Visual Tree\uff09\u662f\u7528\u4e8e\u8868\u793a\u548c\u7ec4\u7ec7UI\u5143\u7d20\u7684\u4e24\u79cd\u6811\u72b6\u7ed3\u6784\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/sanlangcode.com\/wp-content\/uploads\/2023\/06\/image-1-1024x470.png\" alt=\"\" class=\"wp-image-1607\"\/><\/figure>\n\n\n\n<p><strong>\u903b\u8f91\u6811\uff08Logical Tree\uff09\uff1a<\/strong> \u903b\u8f91\u6811\u662f\u7528\u4e8e\u8868\u793aUI\u5143\u7d20\u4e4b\u95f4\u7684\u903b\u8f91\u5173\u7cfb\u7684\u6811\u72b6\u7ed3\u6784\u3002\u5b83\u63cf\u8ff0\u4e86UI\u5143\u7d20\u4e4b\u95f4\u7684\u7236\u5b50\u5173\u7cfb\uff0c\u4ee5\u53ca\u5143\u7d20\u5728\u754c\u9762\u4e0a\u7684\u7ec4\u7ec7\u7ed3\u6784\u3002\u903b\u8f91\u6811\u662f\u7531<code>System.Windows.DependencyObject<\/code>\u6d3e\u751f\u7684\u5bf9\u8c61\u7ec4\u6210\u7684\uff0c\u8fd9\u4e9b\u5bf9\u8c61\u5305\u62ec\u7a97\u53e3\u3001\u9762\u677f\u3001\u63a7\u4ef6\u7b49\u3002<\/p>\n\n\n\n<p>\u903b\u8f91\u6811\u7684\u8282\u70b9\u662f<code>UIElement<\/code>\u5bf9\u8c61\uff0c\u8fd9\u4e9b\u8282\u70b9\u53ef\u4ee5\u5305\u542b\u5176\u4ed6<code>UIElement<\/code>\u5bf9\u8c61\u4f5c\u4e3a\u5b50\u8282\u70b9\u3002\u4f8b\u5982\uff0c\u4e00\u4e2a\u7a97\u53e3\u53ef\u4ee5\u5305\u542b\u4e00\u4e2a\u6839\u5143\u7d20\uff08\u5982<code>Grid<\/code>\u6216<code>StackPanel<\/code>\uff09\uff0c\u6839\u5143\u7d20\u53ef\u4ee5\u5305\u542b\u5176\u4ed6\u5143\u7d20\u4f5c\u4e3a\u5176\u5b50\u5143\u7d20\u3002\u8fd9\u79cd\u7236\u5b50\u5173\u7cfb\u53ef\u4ee5\u901a\u8fc7<code>LogicalTreeHelper<\/code>\u7c7b\u6765\u8bbf\u95ee\u548c\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p>\u903b\u8f91\u6811\u7528\u4e8e\u8868\u793aUI\u5143\u7d20\u4e4b\u95f4\u7684\u903b\u8f91\u7ed3\u6784\uff0c\u4f8b\u5982\u63a7\u4ef6\u7684\u5e03\u5c40\u3001\u63a7\u4ef6\u4e4b\u95f4\u7684\u4e8b\u4ef6\u4f20\u9012\u7b49\u3002\u901a\u8fc7\u903b\u8f91\u6811\uff0cWPF\u53ef\u4ee5\u5b9e\u73b0\u8bf8\u5982\u5e03\u5c40\u3001\u547d\u4ee4\u4f20\u9012\u3001\u4e8b\u4ef6\u8def\u7531\u7b49\u529f\u80fd\u3002<\/p>\n\n\n\n<p><strong>\u89c6\u89c9\u6811\uff08Visual Tree\uff09\uff1a<\/strong> \u89c6\u89c9\u6811\u662f\u7528\u4e8e\u8868\u793aUI\u5143\u7d20\u7684\u53ef\u89c6\u5316\u7ed3\u6784\u7684\u6811\u72b6\u7ed3\u6784\u3002\u5b83\u63cf\u8ff0\u4e86UI\u5143\u7d20\u5728\u5c4f\u5e55\u4e0a\u7684\u663e\u793a\u5173\u7cfb\u548c\u5c42\u6b21\u7ed3\u6784\u3002\u89c6\u89c9\u6811\u662f\u7531<code>System.Windows.Media.Visual<\/code>\u6d3e\u751f\u7684\u5bf9\u8c61\u7ec4\u6210\u7684\uff0c\u8fd9\u4e9b\u5bf9\u8c61\u5305\u62ec\u7a97\u53e3\u3001\u9762\u677f\u3001\u63a7\u4ef6\u3001\u7ed8\u56fe\u5143\u7d20\u7b49\u3002<\/p>\n\n\n\n<p>\u89c6\u89c9\u6811\u7684\u8282\u70b9\u662f<code>Visual<\/code>\u5bf9\u8c61\uff0c\u8fd9\u4e9b\u5bf9\u8c61\u53ef\u4ee5\u5305\u542b\u5176\u4ed6<code>Visual<\/code>\u5bf9\u8c61\u4f5c\u4e3a\u5b50\u8282\u70b9\u3002\u4f8b\u5982\uff0c\u4e00\u4e2a\u7a97\u53e3\u53ef\u4ee5\u5305\u542b\u4e00\u4e2a\u6839\u5143\u7d20\uff08\u5982<code>Grid<\/code>\u6216<code>StackPanel<\/code>\uff09\uff0c\u6839\u5143\u7d20\u53ef\u4ee5\u5305\u542b\u5176\u4ed6\u5143\u7d20\u4f5c\u4e3a\u5176\u5b50\u5143\u7d20\u3002\u89c6\u89c9\u6811\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u90fd\u4e0e\u5c4f\u5e55\u4e0a\u7684\u53ef\u89c6\u5316\u5448\u73b0\u76f8\u5173\u8054\u3002<\/p>\n\n\n\n<p>\u89c6\u89c9\u6811\u7528\u4e8e\u8868\u793aUI\u5143\u7d20\u7684\u53ef\u89c6\u5316\u5c42\u6b21\u7ed3\u6784\uff0c\u5305\u62ec\u5143\u7d20\u7684\u53ef\u89c6\u5316\u5c5e\u6027\uff08\u5982\u5927\u5c0f\u3001\u4f4d\u7f6e\u3001\u6837\u5f0f\u7b49\uff09\u4ee5\u53ca\u4e0e\u6e32\u67d3\u548c\u5e03\u5c40\u76f8\u5173\u7684\u4fe1\u606f\u3002\u901a\u8fc7\u89c6\u89c9\u6811\uff0cWPF\u53ef\u4ee5\u8fdb\u884c\u5143\u7d20\u7684\u53ef\u89c6\u5316\u5e03\u5c40\u3001\u6e32\u67d3\u548c\u4ea4\u4e92\u5904\u7406\u3002<\/p>\n\n\n\n<p>\u903b\u8f91\u6811\u548c\u89c6\u89c9\u6811\u4e4b\u95f4\u5b58\u5728\u4e00\u5bf9\u4e00\u7684\u6620\u5c04\u5173\u7cfb\uff0c\u5373\u903b\u8f91\u6811\u7684\u8282\u70b9\u5bf9\u5e94\u4e8e\u89c6\u89c9\u6811\u7684\u8282\u70b9\u3002\u5b83\u4eec\u4e00\u8d77\u6784\u6210\u4e86WPF\u4e2dUI\u5143\u7d20\u7684\u5b8c\u6574\u63cf\u8ff0\uff0c\u4f7f\u5f97WPF\u80fd\u591f\u8fdb\u884c\u5e03\u5c40\u3001\u6e32\u67d3\u3001\u4e8b\u4ef6\u5904\u7406\u7b49\u64cd\u4f5c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/sanlangcode.com\/wp-content\/uploads\/2023\/06\/image-3-1024x618.png\" alt=\"\" class=\"wp-image-1613\"\/><\/figure>\n\n\n\n<p>\u603b\u7ed3\uff1a \u903b\u8f91\u6811\u63cf\u8ff0\u4e86UI\u5143\u7d20\u4e4b\u95f4\u7684\u903b\u8f91\u5173\u7cfb\uff0c\u7528\u4e8e\u5e03\u5c40\u3001\u547d\u4ee4\u4f20\u9012\u548c\u4e8b\u4ef6\u8def\u7531\u7b49\u529f\u80fd\uff1b\u800c\u89c6\u89c9\u6811\u63cf\u8ff0\u4e86UI\u5143\u7d20\u7684\u53ef\u89c6\u5316\u7ed3\u6784\uff0c\u7528\u4e8e\u53ef\u89c6\u5316\u5e03\u5c40\u3001\u6e32\u67d3<\/p>\n\n\n\n<p><br>\u5f53\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684WPF\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u903b\u8f91\u6811\u548c\u89c6\u89c9\u6811\u662f\u81ea\u52a8\u751f\u6210\u7684\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u6f14\u793a\u4e86\u903b\u8f91\u6811\u548c\u89c6\u89c9\u6811\u7684\u7ed3\u6784\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">xamlCopy code<code>&lt;Window x:Class=\"WpfApp.MainWindow\"\n        xmlns=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation\"\n        xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\"\n        Title=\"WPF App\" Height=\"300\" Width=\"300\"&gt;\n    &lt;Grid&gt;\n        &lt;Button Content=\"Click Me\" HorizontalAlignment=\"Center\" VerticalAlignment=\"Center\" Click=\"Button_Click\" \/&gt;\n    &lt;\/Grid&gt;\n&lt;\/Window&gt;\n<\/code><\/pre>\n\n\n\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a<code>MainWindow<\/code>\u7684\u7a97\u53e3\uff0c\u5e76\u5728\u7a97\u53e3\u4e2d\u653e\u7f6e\u4e86\u4e00\u4e2a<code>Button<\/code>\u63a7\u4ef6\u3002<\/p>\n\n\n\n<p>\u903b\u8f91\u6811\u7684\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>MainWindow<\/code>\uff1a\u6839\u8282\u70b9\uff0c\u8868\u793a\u7a97\u53e3\u3002<ul><li><code>Grid<\/code>\uff1a<code>MainWindow<\/code>\u7684\u5b50\u8282\u70b9\uff0c\u8868\u793a\u4e00\u4e2a\u7f51\u683c\u5bb9\u5668\u3002<ul><li><code>Button<\/code>\uff1a<code>Grid<\/code>\u7684\u5b50\u8282\u70b9\uff0c\u8868\u793a\u4e00\u4e2a\u6309\u94ae\u3002<\/li><\/ul><\/li><\/ul><\/li><\/ul>\n\n\n\n<p>\u89c6\u89c9\u6811\u7684\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>Window<\/code>\uff1a\u6839\u8282\u70b9\uff0c\u8868\u793a\u7a97\u53e3\u3002<ul><li><code>Grid<\/code>\uff1a<code>Window<\/code>\u7684\u5b50\u8282\u70b9\uff0c\u8868\u793a\u4e00\u4e2a\u7f51\u683c\u5bb9\u5668\u3002<ul><li><code>Button<\/code>\uff1a<code>Grid<\/code>\u7684\u5b50\u8282\u70b9\uff0c\u8868\u793a\u4e00\u4e2a\u6309\u94ae\u3002<\/li><\/ul><\/li><\/ul><\/li><\/ul>\n\n\n\n<p>\u8fd9\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\u5c55\u793a\u4e86\u903b\u8f91\u6811\u548c\u89c6\u89c9\u6811\u7684\u57fa\u672c\u7ed3\u6784\u3002\u5728\u5b9e\u9645\u7684WPF\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u6811\u7684\u7ed3\u6784\u4f1a\u66f4\u52a0\u590d\u6742\uff0c\u5305\u542b\u66f4\u591a\u7684\u5143\u7d20\u548c\u5bb9\u5668\uff0c\u4f46\u662f\u5b83\u4eec\u7684\u7ec4\u7ec7\u539f\u5219\u548c\u5173\u7cfb\u662f\u76f8\u4f3c\u7684\u3002<\/p>\n\n\n\n<p>\u901a\u8fc7\u903b\u8f91\u6811\u548c\u89c6\u89c9\u6811\uff0cWPF\u53ef\u4ee5\u6b63\u786e\u5730\u5e03\u5c40\u548c\u6e32\u67d3UI\u5143\u7d20\uff0c\u5e76\u5904\u7406\u4e0e\u5176\u76f8\u5173\u7684\u4e8b\u4ef6\u548c\u4ea4\u4e92\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728WPF\u4e2d\uff0c\u903b\u8f91\u6811\uff08Logica&#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-1605","post","type-post","status-publish","format-standard","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1605","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=1605"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1605\/revisions"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=1605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=1605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=1605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}