{"id":3542,"date":"2012-06-27T11:32:04","date_gmt":"2012-06-27T02:32:04","guid":{"rendered":"http:\/\/www.moonmile.net\/blog\/archives\/3542"},"modified":"2012-06-28T05:15:30","modified_gmt":"2012-06-27T20:15:30","slug":"ccx-metro-%e3%81%ae%e5%a0%b4%e5%90%88-mvvm-%e3%81%8c%e3%81%a9%e3%81%ae%e3%82%88%e3%81%86%e3%81%ab%e5%ae%9f%e8%a3%85%e3%81%95%e3%82%8c%e3%81%a6%e3%81%84%e3%82%8b%e3%81%8b","status":"publish","type":"post","link":"http:\/\/www.moonmile.net\/blog\/archives\/3542","title":{"rendered":"c++\/cx metro \u306e\u5834\u5408 mvvm \u304c\u3069\u306e\u3088\u3046\u306b\u5b9f\u88c5\u3055\u308c\u3066\u3044\u308b\u304b"},"content":{"rendered":"<p>\u3068\u3044\u3046\u30e1\u30e2\u66f8\u304d\u3002<br \/>\nmetro application \u3067 grid \u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u958b\u304f\u3068\u3001Common \u3068\u3044\u3046\u30d5\u30a9\u30eb\u30c0\u304c\u4f5c\u3089\u308c\u3066\u3001\u305d\u306e\u4e2d\u306b ListView \u3092\u4f7f\u3063\u305f mvvm \u306e\u5b9f\u88c5\u304c\u3042\u308a\u307e\u3059\u3002WPF, Siverlight \u3068\u5b9f\u88c5\u304c\u7570\u306a\u308b\u306e\u3067\u3001\u899a\u3048\u76f4\u3057\u306b\u306a\u308b\u306e\u304b\uff1f\u3068\u3046\u3053\u3068\u3068\u3001\u3053\u306e\u30af\u30e9\u30b9\u3092\u4f7f\u3063\u3066\u5b9f\u88c5\u3057\u3066\u826f\u3044\u306e\u304b\uff1f\u3068\u3044\u3046\u3053\u3068\u304c\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u4eca\u5f8c\u306a\u3057\u5d29\u3057\u306b\u6d3b\u7528\u3055\u308c\u305d\u3046\u306a\u4e88\u611f\u306f\u3057\u307e\u3059\u3002<\/p>\n<p>Visual Studio 2012 RC\u306eMetro \u30b9\u30bf\u30a4\u30eb \u30a2\u30d7\u30ea\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u898b\u3066\u307f\u308b &#8211; \u304b\u305a\u304d\u306eBlog@Hatena<br \/>\n<a href=\"http:\/\/d.hatena.ne.jp\/okazuki\/20120604\/1338821522\">http:\/\/d.hatena.ne.jp\/okazuki\/20120604\/1338821522<\/a><\/p>\n<p>\u306e\u3068\u3053\u308d\u3092\u53c2\u7167\u306b\u3057\u3066\u3001<br \/>\n\u30fbSampleDataSource.h<br \/>\n\u30fbSampleDataSource.cpp<br \/>\n\u30fbBindableBase.h<br \/>\n\u30fbBindableBase.cpp<br \/>\n\u3060\u3051\u898b\u3066\u3044\u304d\u307e\u3059\u3002\u69cb\u9020\u306f\u3001C# \u3068\u4e00\u7dd2\u3067\u3059\u3002<\/p>\n<p><a href=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2012\/06\/wpid-dworkblogimage20120627_01org.jpg\"><img decoding=\"async\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2012\/06\/wpid-dworkblogimage20120627_01thum.jpg\" border=\"0\" \/><\/a><\/p>\n<p>\u25a0SampleDataSource.h<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/\/ &lt;summary&gt;\r\n\/\/\/ Base class for &lt;see cref=&amp;quot;SampleDataItem&amp;quot;\/&gt; and &lt;see cref=&amp;quot;SampleDataGroup&amp;quot;\/&gt; that\r\n\/\/\/ defines properties common to both.\r\n\/\/\/ &lt;\/summary&gt;\r\n &#x5B;Windows::Foundation::Metadata::WebHostHidden]\r\n &#x5B;Windows::UI::Xaml::Data::Bindable]\r\npublic ref class SampleDataCommon : CppNotify::Common::BindableBase\r\n{\r\ninternal:\r\n\tSampleDataCommon(Platform::String^ uniqueId, Platform::String^ title, Platform::String^ subtitle, Platform::String^ imagePath,\r\n\t\tPlatform::String^ description);\r\n\r\npublic:\r\n\tvoid SetImage(Platform::String^ path);\r\n\r\n\tproperty Platform::String^ UniqueId { Platform::String^ get(); void set(Platform::String^ value); }\r\n\tproperty Platform::String^ Title { Platform::String^ get(); void set(Platform::String^ value); }\r\n\tproperty Platform::String^ Subtitle { Platform::String^ get(); void set(Platform::String^ value); }\r\n\tproperty Windows::UI::Xaml::Media::ImageSource^ Image { Windows::UI::Xaml::Media::ImageSource^ get(); void set(Windows::UI::Xaml::Media::ImageSource^ value); }\r\n\tproperty Platform::String^ Description { Platform::String^ get(); void set(Platform::String^ value); }\r\n\r\nprivate:\r\n\tPlatform::String^ _uniqueId;\r\n\tPlatform::String^ _title;\r\n\tPlatform::String^ _subtitle;\r\n\tWindows::UI::Xaml::Media::ImageSource^ _image;\r\n\tPlatform::String^ _imagePath;\r\n\tPlatform::String^ _description;\r\n};\r\n<\/pre>\n<p>ListView \u306e Item \u3092\u5236\u5fa1\u3059\u308b\u3068\u3053\u308d\u3067\u3001\u5b9f\u969b\u306b\u306f SampleDataCommon \u3092\u7d99\u627f\u3057\u3066 SampleDataItem \u3092\u4f5c\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n\u5b9f\u969b\u306e Notify \u306e\u3068\u3053\u308d\u306f\u3001BindableBase \u30af\u30e9\u30b9\u3067\u5b9f\u88c5\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\nC++\/CX \u306a\u306e\u3067\u30d7\u30ed\u30d1\u30c6\u30a3\u306f\u300cproperty\u300d\u3092\u4f7f\u3063\u3066\u4f5c\u308c\u307e\u3059\u3002<\/p>\n<p>\u25a0SampleDataSource.cpp<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nSampleDataCommon::SampleDataCommon(String^ uniqueId, String^ title, String^ subtitle, String^ imagePath, String^ description)\r\n{\r\n\t_uniqueId = uniqueId;\r\n\t_title = title;\r\n\t_subtitle = subtitle;\r\n\t_description = description;\r\n\t_imagePath = imagePath;\r\n\t_image = nullptr;\r\n}\r\n\r\nString^ SampleDataCommon::UniqueId::get()\r\n{\r\n\treturn _uniqueId;\r\n}\r\n\r\nvoid SampleDataCommon::UniqueId::set(String^ value)\r\n{\r\n\tif (_uniqueId != value)\r\n\t{\r\n\t\t_uniqueId = value;\r\n\t\tOnPropertyChanged(&quot;UniqueId&quot;);\r\n\t}\r\n}\r\n<\/pre>\n<p>\u5fa1\u99b4\u67d3\u307f\u306e OnPropertyChanged \u547c\u3073\u51fa\u3057\u304c\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u306e set \u30e1\u30bd\u30c3\u30c9\u306e\u4e2d\u306b\u3042\u308a\u307e\u3059\u3002<br \/>\nOnPropertyChanged \u306b\u6e21\u3059\u306e\u306f\u3001C# \u3068\u540c\u3058\u3088\u3046\u306b\u6587\u5b57\u5217\u3067\u3059\u306d\u3002\u7d30\u304b\u3044\u3053\u3068\u3067\u3059\u304c\u3001C++\/CX \u306e\u5834\u5408\u306f Platform::String \u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u25a0BindableBase.h<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/\/ &lt;summary&gt;\r\n\/\/\/ Implementation of &lt;see cref=&amp;quot;INotifyPropertyChanged&amp;quot;\/&gt; to simplify models.\r\n\/\/\/ &lt;\/summary&gt;\r\n &#x5B;Windows::Foundation::Metadata::WebHostHidden]\r\npublic ref class BindableBase : Windows::UI::Xaml::Data::INotifyPropertyChanged\r\n{\r\npublic:\r\n\tvirtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ PropertyChanged;\r\n\r\nprotected:\r\n\tvirtual void OnPropertyChanged(Platform::String^ propertyName);\r\n};\r\n<\/pre>\n<p>BindableBase \u306e\u4e2d\u8eab\u306f\u7c21\u5358\u3067\u3001Model \u304b\u3089\u30d7\u30ed\u30d1\u30c6\u30a3\u66f4\u65b0\u3092\u53d7\u3051\u53d6\u308b\u305f\u3081\u306e OnPropertyChanged \u3068\u3001XAML \u306b\u66f4\u65b0\u901a\u77e5\u3092\u3059\u308b\u305f\u3081\u306e PropertyChanged \u3060\u3051\u3067\u3059\u3002C# \u306b\u3042\u308b SetProperty \u76f8\u5f53\u306e\u3082\u306e\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u3061\u306a\u307f\u3001\u300cModel \u304c\u66f4\u65b0\u901a\u77e5\u7528\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059\u300d\u306e\u3067\u300cOnPropertyChanged\u300d\u3058\u3083\u306a\u304f\u3066\u300cRaisePropertyChanged\u300d\u3068\u304b\u300cChangeProperty\u300d\u3068\u304b\u306e\u307b\u3046\u304c\u826f\u3044\u6c17\u304c\u3059\u308b\u306e\u3067\u3059\u304c\u3001\u3069\u3046\u306a\u3093\u3067\u3057\u3087\u3046\uff1f\u3044\u304f\u3064\u304b\u306e mvvm \u7528\u306e\u30b5\u30f3\u30d7\u30eb\u3092\u63a2\u3059\u3068 OnPropertyChanged \u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u308c\u3092\u8e0f\u8972\u3057\u305f\u6a21\u69d8\u3067\u3059\u3002<\/p>\n<p>\u25a0BindableBase.cpp<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/\/ &lt;summary&gt;\r\n\/\/\/ Notifies listeners that a property value has changed.\r\n\/\/\/ &lt;\/summary&gt;\r\n\/\/\/ &lt;param name=&amp;quot;propertyName&amp;quot;&gt;Name of the property used to notify listeners.&lt;\/param&gt;\r\nvoid BindableBase::OnPropertyChanged(String^ propertyName)\r\n{\r\n\tPropertyChanged(this, ref new PropertyChangedEventArgs(propertyName));\r\n}\r\n<\/pre>\n<p>\u5b9f\u88c5\u306e\u307b\u3046\u3082\u7c21\u5358\u3067\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u300c\u6587\u5b57\u5217\u300d\u3092\u53d7\u3051\u53d6\u3063\u3066\u3001PropertyChanged \u3092\u5b9f\u884c\u3057\u3066\u3044\u308b\u3060\u3051\u3067\u3059\u3002\u3053\u306e PropertyChanged \u306f\u3001XAML \u5074\u304b\u3089\u767b\u9332\u3055\u308c\u308b\u3082\u306e\u3067\u3059\u3002\u30d7\u30ed\u30d1\u30c6\u30a3\u540d\u3092\u76f4\u63a5\u6e21\u3055\u305a\u306b\u3001PropertyChangedEventArgs \u3067\u5305\u3080\u3068\u3053\u308d\u304c\u5197\u9577\u306a\u6c17\u304c\u3057\u307e\u3059\u304c\uff08\u7279\u306b ref new \u306b\u306a\u3063\u3066\u3044\u308b\u3068\u3053\u308d\uff09\u3001\u5f15\u6570\u306e\u578b\u3092\u56fa\u5b9a\u3057\u305f\u304b\u3063\u305f\u306a\u306e\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u25a0\u5c11\u3057\u697d\u3092\u3059\u308b\u305f\u3081\u306b\u30de\u30af\u30ed\u3092\u66f8\u304f<\/p>\n<p>\u3068\u3044\u3046\u8a33\u3067\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u306e set\/get \u3092\u66f8\u304f\u3068\u3053\u308d\u306f mvvm \u3067\u304a\u306a\u3058\u307f\u306e\u3068\u3053\u308d\u3067\u3059\u3002C# \u3067\u306f\u3001CallerMemberName \u3068\u3044\u3046\u5c5e\u6027\u304c\u3042\u308a\u307e\u3059\u304c\u3001C++\/CX \u306e\u5834\u5408\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u7406\u7531\u306f\u3088\u304f\u308f\u304b\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u3055\u3066\u3001\u3053\u3053\u306e get\/set \u3092\u66f8\u304f\u306e\u306f\u7d50\u69cb\u9762\u5012\u3067\u3059\u3002\u307e\u3042\u3001T4 \u3092\u4f7f\u3063\u3066\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5316\u3057\u3066\u3057\u307e\u3063\u3066\u3082\u826f\u3044\u306e\u3067\u3059\u304c\u3001C++\/CX \u306e\u5834\u5408\u306f C\/C++ \u7cfb\u5217\u3068\u3057\u3066\u30de\u30af\u30ed\u3092\u4f7f\u3046\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n#define PROPERTY( _t, _m )\t\t\t\t\\\r\nprivate:\t\t\t\t\t\t\t\t\\\r\n\t_t m_##_m;\t\t\t\t\t\t\t\\\r\npublic:\t\t\t\t\t\t\t\t\t\\\r\n\tproperty _t _m {\t\t\t\t\t\\\r\n\t\t_t get() { return m_##_m; }\t\t\\\r\n\t\tvoid set( _t value ) {\t\t\t\\\r\n\t\t\tif ( m_##_m != value ) {\t\\\r\n\t\t\t\tm_##_m = value;\t\t\t\\\r\n\t\t\t\tOnPropertyChanged( #_m ); \\\r\n\t\t}}}\r\n<\/pre>\n<p>\u3053\u308c\u3092\u4f7f\u3063\u3066\u3001SampleDataSource.cpp \u3092\u66f8\u304d\u63db\u3048\u307e\u3059\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/\/ &lt;summary&gt;\r\n\/\/\/ Base class for &lt;see cref=&amp;quot;SampleDataItem&amp;quot;\/&gt; and &lt;see cref=&amp;quot;SampleDataGroup&amp;quot;\/&gt; that\r\n\/\/\/ defines properties common to both.\r\n\/\/\/ &lt;\/summary&gt;\r\n &#x5B;Windows::Foundation::Metadata::WebHostHidden]\r\n &#x5B;Windows::UI::Xaml::Data::Bindable]\r\npublic ref class SampleDataCommon : CppNotify::Common::BindableBase\r\n{\r\ninternal:\r\n\tSampleDataCommon(Platform::String^ uniqueId, Platform::String^ title, Platform::String^ subtitle, Platform::String^ imagePath,\r\n\t\tPlatform::String^ description);\r\n\r\npublic:\r\n\tvoid SetImage(Platform::String^ path);\r\n\r\n\tPROPERTY( Platform::String^, UniqueId );\r\n\tPROPERTY( Platform::String^, Title );\r\n\tPROPERTY( Platform::String^, Subtitle );\r\n\t\/\/ PROPERTY( Windows::UI::Xaml::Media::ImageSource^, Image );\r\n\tproperty Windows::UI::Xaml::Media::ImageSource^ Image { Windows::UI::Xaml::Media::ImageSource^ get(); void set(Windows::UI::Xaml::Media::ImageSource^ value); }\r\n\tPROPERTY( Platform::String^, Description );\r\nprivate:\r\n\tWindows::UI::Xaml::Media::ImageSource^ _image;\r\n\tPlatform::String^ _imagePath;\r\n};\r\n<\/pre>\n<p>private \u306a\u30e1\u30f3\u30d0\u304c\u300cm_Title\u300d\u306e\u3088\u3046\u306b\u30d7\u30ed\u30d1\u30c6\u30a3\u540d\u306b\u30d7\u30ec\u30d5\u30a3\u30c3\u30af\u30b9\u304c\u4ed8\u3044\u305f\u5f62\u5f0f\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u304c\u3001\u3053\u308c\u3067\u826f\u3044\u304b\u3068\u3002<br \/>\nImage \u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u5834\u5408\u306f\u3001_imagePath \u3068\u306e\u7d61\u307f\u3082\u3042\u308b\u306e\u3067\u3001\u5225\u9014\u5b9a\u7fa9\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u25a0OnPropertyChanged\u306b\u6e21\u3059\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u6587\u5b57\u5217\u4ee5\u5916\u306b\u3057\u305f\u3044\u3002<\/p>\n<p>\u3053\u308c\u3092\u8e0f\u307e\u3048\u3066\u3001C++\u306e\u30d1\u30bf\u30fc\u30f3\u3068\u3001C++\/CX \u306e\u5225\u306e\u30d1\u30bf\u30fc\u30f3\u3068\u8003\u3048\u3066\u3044\u3053\u3046\u3068\u3044\u3046\u8a33\u3067\u3059\u3002<br \/>\n\u95a2\u6570\u30dd\u30a4\u30f3\u30bf\u3092\u4f7f\u3046\u304b\u3001\u81ea\u52d5\u306a enum \u3092\u4f7f\u3046\u304b\u3001\u3068\u3044\u3046\u5f62\u3067\u6587\u5b57\u5217\u3092\u4f7f\u308f\u306a\u3044\u3088\u3046\u306b\u4f5c\u308a\u5909\u3048\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3068\u3044\u3046\u30e1\u30e2\u66f8\u304d\u3002 metro application \u3067 grid \u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u958b\u304f\u3068\u3001Common \u3068\u3044\u3046\u30d5\u30a9\u30eb\u30c0\u304c\u4f5c\u3089\u308c\u3066\u3001\u305d\u306e\u4e2d\u306b ListView \u3092\u4f7f\u3063\u305f mvvm \u306e\u5b9f\u88c5\u304c\u3042\u308a\u307e\u3059\u3002WPF, Siverl &hellip; <a href=\"http:\/\/www.moonmile.net\/blog\/archives\/3542\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[46],"tags":[],"class_list":["post-3542","post","type-post","status-publish","format-standard","hentry","category-ccx"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/3542","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/comments?post=3542"}],"version-history":[{"count":4,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/3542\/revisions"}],"predecessor-version":[{"id":3544,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/3542\/revisions\/3544"}],"wp:attachment":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=3542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=3542"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=3542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}