{"id":883,"date":"2021-09-16T12:26:38","date_gmt":"2021-09-16T04:26:38","guid":{"rendered":"http:\/\/www.wayln.com\/?p=883"},"modified":"2021-09-16T12:26:38","modified_gmt":"2021-09-16T04:26:38","slug":"%e5%b1%9e%e6%80%a7%e9%aa%8c%e8%af%81","status":"publish","type":"post","link":"https:\/\/www.wayln.com\/?p=883","title":{"rendered":"\u5c5e\u6027\u9a8c\u8bc1"},"content":{"rendered":"<p>\u5728\u5b9a\u4e49\u4efb\u4f55\u7c7b\u578b\u7684\u5c5e\u6027\u65f6\uff0c\u90fd\u9700\u8981\u9762\u5bf9\u9519\u8bef\u8bbe\u7f6e\u5c5e\u6027\u7684\u53ef\u80fd\u6027\uff0c\u5bf9\u4e8e\u4f20\u7edf\u7684.Net\u5c5e\u6027\uff0c\u53ef\u5c1d\u8bd5\u5728\u5c5e\u6027\u8bbe\u7f6e\u5176\u4e2d\u6355\u83b7\u8fd9\u7c7b\u95ee\u9898\uff0c\u4f46\u5bf9\u4e8e\u4f9d\u8d56\u9879\u5c5e\u6027\u800c\u8a00\uff0c\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u5408\u9002\uff0c\u56e0\u4e3a\u53ef\u80fd\u901a\u8fc7WPF\u5c5e\u6027\u7cfb\u7edf\u4f7f\u7528SetValue()\u65b9\u6cd5\u76f4\u63a5\u8bbe\u7f6e\u5c5e\u6027\u3002<br \/>\n&#8211; ValidateValueCallback:\u8be5\u56de\u8c03\u51fd\u6570\u53ef\u63a5\u53d7\u6216\u62d2\u7edd\u65b0\u503c\u3002\u901a\u5e38\uff0c\u8be5\u56de\u8c03\u51fd\u6570\u7528\u4e8e\u6355\u83b7\u8fdd\u53cd\u5c5e\u6027\u7ea6\u675f\u7684\u660e\u663e\u9519\u8bef\uff0c\u53ef\u4f5c\u4e3aDependencyProperty.Register()\u65b9\u6cd5\u7684\u4e00\u4e2a\u53c2\u6570\u63d0\u4f9b\u8be5\u56de\u8c03\u51fd\u6570\u3002<br \/>\n&#8211; CoerceValueCallback:\u8be5\u56de\u8c03\u51fd\u6570\u53ef\u5c06\u65b0\u503c\u4fee\u6539\u4e3a\u66f4\u80fd\u88ab\u63a5\u53d7\u7684\u503c\u3002\u8be5\u56de\u8c03\u51fd\u6570\u901a\u5e38\u7528\u4e8e\u5904\u7406\u4e3a\u76f8\u540c\u5bf9\u8c61\u8bbe\u7f6e\u7684\u4f9d\u8d56\u9879\u5c5e\u6027\u503c\u76f8\u4e92\u51b2\u7a81\u7684\u95ee\u9898\uff0c\u8fd9\u4e9b\u503c\u672c\u8eab\u53ef\u80fd\u662f\u5408\u6cd5\u7684\uff0c\u4f46\u5f53\u540c\u65f6\u5e94\u7528\u65f6\u4ed6\u4eec\u662f\u4e0d\u76f8\u5bb9\u7684\u3002\u4e3a\u4e86\u4f7f\u7528\u8fd9\u4e2a\u56de\u8c03\u51fd\u6570\uff0c\u5f53\u521b\u5efaFrameworkPropertyMetadata\u5bf9\u8c61\u65f6\uff0c\u4f5c\u4e3a\u6784\u9020\u51fd\u6570\u7684\u4e00\u4e2a\u53c2\u6570\u63d0\u4f9b\u8be5\u56de\u8c03\u51fd\u6570\u3002<br \/>\n\u5f53\u5e94\u7528\u7a0b\u5e8f\u8bd5\u56fe\u8bbe\u7f6e\u4f9d\u8d56\u9879\u5c5e\u6027\u65f6\uff0c\u6240\u6709\u8fd9\u4e9b\u5185\u5bb9\u7684\u4f5c\u7528\u8fc7\u7a0b\uff1a<br \/>\n1. \u9996\u5148\uff0cCoerceValueCallback\u65b9\u6cd5\u6709\u673a\u4f1a\u4fee\u6539\u63d0\u4f9b\u7684\u503c\uff0c\u6216\u8005\u8fd4\u56deDependencyProperty.UnsetValue,\u8fd9\u56de\u5b8c\u5168\u62d2\u7edd\u4fee\u6539\u3002<br \/>\n2. \u63a5\u4e0b\u6765\u6fc0\u6d3bValidateValueCallback\u65b9\u6cd5\u3002\u8be5\u65b9\u6cd5\u8fd4\u56detrue\u4ee5\u63a5\u53d7\u4e00\u4e2a\u503c\u4f5c\u4e3a\u5408\u6cd5\u503c\uff0c\u6216\u8005\u8fd4\u56defalse\u62d2\u7edd\u503c\u3002\u4e0eCoerceValueCallback\u65b9\u6cd5\u4e0d\u540c\uff0cValidateValueCallback\u65b9\u6cd5\u4e0d\u80fd\u8bbf\u95ee\u8bbe\u7f6e\u5c5e\u6027\u7684\u4e8b\u8ff9\u5bf9\u8c61\uff0c\u8fd9\u610f\u5473\u7740\u60a8\u4e0d\u80fd\u68c0\u67e5\u5176\u4ed6\u5c5e\u6027\u503c\u3002<br \/>\n3. \u6700\u540e\uff0c\u5982\u679c\u524d\u4e24\u4e2a\u9636\u6bb5\u90fd\u83b7\u5f97\u6210\u529f\uff0c\u5c31\u4f1a\u89e6\u53d1PropertyChangedCallback\u65b9\u6cd5\u3002\u6b64\u65f6\uff0c\u5982\u679c\u5e0c\u671b\u4e3a\u5176\u4ed6\u7c7b\u63d0\u4f9b\u901a\u77e5\uff0c\u53ef\u4ee5\u5f15\u53d1\u66f4\u6539\u4e8b\u4ef6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5b9a\u4e49\u4efb\u4f55\u7c7b\u578b\u7684\u5c5e\u6027\u65f6\uff0c\u90fd\u9700\u8981\u9762\u5bf9\u9519\u8bef\u8bbe\u7f6e\u5c5e\u6027\u7684\u53ef\u80fd\u6027\uff0c\u5bf9\u4e8e\u4f20\u7edf\u7684.Net\u5c5e\u6027\uff0c\u53ef\u5c1d\u8bd5\u5728\u5c5e\u6027\u8bbe\u7f6e\u5176\u4e2d\u6355\u83b7\u8fd9\u7c7b\u95ee [&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-883","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\/883","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=883"}],"version-history":[{"count":1,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/883\/revisions"}],"predecessor-version":[{"id":884,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/883\/revisions\/884"}],"wp:attachment":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}