{"id":881,"date":"2021-09-15T23:26:22","date_gmt":"2021-09-15T15:26:22","guid":{"rendered":"http:\/\/www.wayln.com\/?p=881"},"modified":"2021-09-15T23:26:22","modified_gmt":"2021-09-15T15:26:22","slug":"%e9%99%84%e5%8a%a0%e7%9a%84%e4%be%9d%e8%b5%96%e9%a1%b9%e5%b1%9e%e6%80%a7","status":"publish","type":"post","link":"https:\/\/www.wayln.com\/?p=881","title":{"rendered":"\u9644\u52a0\u7684\u4f9d\u8d56\u9879\u5c5e\u6027"},"content":{"rendered":"<p>\u9644\u52a0\u5c5e\u6027\u662f\u4e00\u79cd\u4f9d\u8d56\u9879\u5c5e\u6027\uff0c\u6709WPF\u5c5e\u6027\u7cfb\u7edf\u7ba1\u7406\uff0c\u4e0d\u540c\u4e4b\u5904\u5728\u4e8e\u9644\u52a0\u5c5e\u6027\u88ab\u5e94\u7528\u5230\u7684\u7c7b\u5e76\u975e\u5b9a\u4e49\u9644\u52a0\u5c5e\u6027\u7684\u90a3\u4e2a\u7c7b<br \/>\n\u4e3a\u4e86\u5b9a\u4e49\u9644\u52a0\u5c5e\u6027\uff0c\u9700\u8981\u4f7f\u7528RegisterAttached()\u65b9\u6cd5\uff0c\u800c\u4e0d\u662f\u4f7f\u7528Register\uff08\uff09\u65b9\u6cd5\u3002<\/p>\n<pre><code class=\"language-CSharp line-numbers\">FrameworkPropertyMetadata metadata=new FrameworkPropertyMetadata(0,new PropertyChangedCallback(Grid.OncellAttachedPropertyChanged));\nGrid.RowProperty=DependencyProperty.RegisterAttached(\"Row\",typeof(int),typeof(Gird),metadata,new ValidataValueCallback(Grid.IsIntValueNotNegative));\n<\/code><\/pre>\n<p>\u5f53\u521b\u5efa\u9644\u52a0\u5c5e\u6027\u65f6\uff0c\u4e0d\u5fc5\u5b9a\u4e49.Net\u5c5e\u6027\u5c01\u88c5\u5668\u3002\u526f\u9a7e\u9a76\u5bfb\u6839\u9700\u8981\u8c03\u7528\u4e24\u4e2a\u9759\u6001\u65b9\u6cd5\u6765\u8bbe\u7f6e\u548c\u83b7\u53d6\uff0cSetValue()\u548cGetValue(),\u7ee7\u627f\u81eaDependencyObject<\/p>\n<pre><code class=\"language-CSharp line-numbers\">public static int GetRow(UIElement element)\n{\n    if(element==null)\n    {\n        throw new ArgumentNullException();\n    }\n    return (int element.GetValue(Grid.RowProperty));\n}\npublic static VOID SetRow(UIElement element,int value)\n{\n    if(element==null)\n    {\n        throw new ArgumentNullException();\n    }\n    element.SetValue(Grid.RowProperty,value);\n}\n<\/code><\/pre>\n<p>\u4e0b\u9762\u793a\u4f8b\u4f7f\u7528\u4ee3\u7801\u5c06\u5143\u7d20\u653e\u5728Grid\u7b2c\u4e00\u884c<\/p>\n<pre><code class=\"language-CSharp line-numbers\">Grid.SetRow(txtElement,0);\n<\/code><\/pre>\n<p>\u4e5f\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528SetValue()\u6216\u8005GetValue\uff0c\u4ece\u800c\u7ed5\u8fc7\u8fd9\u4e24\u4e2a\u9759\u6001\u65b9\u6cd5<\/p>\n<pre><code class=\"language-CSharp line-numbers\">txtElement.SetValue(Gird.RowProperty,0);\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9644\u52a0\u5c5e\u6027\u662f\u4e00\u79cd\u4f9d\u8d56\u9879\u5c5e\u6027\uff0c\u6709WPF\u5c5e\u6027\u7cfb\u7edf\u7ba1\u7406\uff0c\u4e0d\u540c\u4e4b\u5904\u5728\u4e8e\u9644\u52a0\u5c5e\u6027\u88ab\u5e94\u7528\u5230\u7684\u7c7b\u5e76\u975e\u5b9a\u4e49\u9644\u52a0\u5c5e\u6027\u7684\u90a3\u4e2a\u7c7b \u4e3a\u4e86 [&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-881","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\/881","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=881"}],"version-history":[{"count":1,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/881\/revisions"}],"predecessor-version":[{"id":882,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/881\/revisions\/882"}],"wp:attachment":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}