{"id":1418,"date":"2019-09-05T00:33:20","date_gmt":"2019-09-04T15:33:20","guid":{"rendered":"https:\/\/blog.minatoproject.com\/?p=1418"},"modified":"2020-02-07T22:24:43","modified_gmt":"2020-02-07T13:24:43","slug":"%e3%80%90prism%e3%80%91usercontrol%e5%88%9d%e6%9c%9f%e5%8c%96%e6%99%82%e3%81%abviewmodel%e3%81%ae%e3%83%97%e3%83%ad%e3%83%91%e3%83%86%e3%82%a3%e3%82%82%e8%a8%ad%e5%ae%9a%e3%81%99%e3%82%8b%e6%96%b9","status":"publish","type":"post","link":"https:\/\/blog.minatoproject.com\/?p=1418","title":{"rendered":"\u3010Prism\u3011UserControl\u521d\u671f\u5316\u6642\u306bViewModel\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3082\u8a2d\u5b9a\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<div class=\"veu_autoEyeCatchBox\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/blog.minatoproject.com\/wp-content\/uploads\/2019\/09\/20190905_eyecatch-1024x576.png\" class=\"attachment-large size-large wp-post-image\" alt=\"\" srcset=\"https:\/\/blog.minatoproject.com\/wp-content\/uploads\/2019\/09\/20190905_eyecatch-1024x576.png 1024w, https:\/\/blog.minatoproject.com\/wp-content\/uploads\/2019\/09\/20190905_eyecatch-300x169.png 300w, https:\/\/blog.minatoproject.com\/wp-content\/uploads\/2019\/09\/20190905_eyecatch-768x432.png 768w, https:\/\/blog.minatoproject.com\/wp-content\/uploads\/2019\/09\/20190905_eyecatch-320x180.png 320w, https:\/\/blog.minatoproject.com\/wp-content\/uploads\/2019\/09\/20190905_eyecatch.png 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/div>\n<h2 class=\"wp-block-heading\">What is this?<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/blog.minatoproject.com\/wp-content\/uploads\/2019\/09\/PrismApplication.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1490\" height=\"1012\" src=\"http:\/\/blog.minatoproject.com\/wp-content\/uploads\/2019\/09\/PrismApplication.png\" alt=\"\" class=\"wp-image-1419\" srcset=\"https:\/\/blog.minatoproject.com\/wp-content\/uploads\/2019\/09\/PrismApplication.png 1490w, https:\/\/blog.minatoproject.com\/wp-content\/uploads\/2019\/09\/PrismApplication-300x204.png 300w, https:\/\/blog.minatoproject.com\/wp-content\/uploads\/2019\/09\/PrismApplication-768x522.png 768w, https:\/\/blog.minatoproject.com\/wp-content\/uploads\/2019\/09\/PrismApplication-1024x695.png 1024w\" sizes=\"auto, (max-width: 1490px) 100vw, 1490px\" \/><\/a><\/figure>\n\n\n\n<p>WPF\u3067Prism\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3092\u4f7f\u3063\u3066\u3044\u308b\u74b0\u5883\u3067\u3001ItemsControl\u306a\u3093\u304b\u306e\u4e2d\u3067\u8907\u6570\u306e\u30ab\u30b9\u30bf\u30e0UserControl\u3092\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u5909\u66f4\u3057\u3064\u3064\u751f\u6210\u3057\u305f\u3044\u5834\u5408\u3001\u901a\u5e38\u306e\u72b6\u614b\u3060\u3068\u751f\u6210\u5143\uff08\u89aaWindow\u306a\u3069\uff09\u306eViewModel\u3067UserControl\u306eViewModel\u3092\u611a\u76f4\u306bnew\u3057\u3066\u3082\u30d7\u30ed\u30d1\u30c6\u30a3\u304c\u8a2d\u5b9a\u3067\u304d\u306a\u3044\u3068\u3044\u3046\u4e8b\u614b\u306b\u9665\u308b\u306e\u3067\u3001\u305d\u306e\u89e3\u6c7a\u7b56\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u6587\u7ae0\u306b\u3059\u308b\u3068\u3084\u3084\u3053\u3057\u3044\u3067\u3059\u304c\u3001\u3084\u308d\u3046\u3068\u3057\u3066\u3044\u305f\u306e\u306f\u3053\u3046\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plane\" data-file=\"MainWindow.xaml\"><code>&lt;ItemsControl ItemsSource=&quot;{Binding UserControls}&quot;&gt;\n    &lt;ItemsControl.ItemsPanel&gt;\n        &lt;ItemsPanelTemplate&gt;\n            &lt;StackPanel Orientation=&quot;Vertical&quot; \/&gt;\n        &lt;\/ItemsPanelTemplate&gt;\n    &lt;\/ItemsControl.ItemsPanel&gt;\n    &lt;ItemsControl.ItemTemplate&gt;\n        &lt;DataTemplate DataType=&quot;{x:Type vm:SampleUserControlViewModel}&quot;&gt;\n            &lt;v:SampleUserControl \/&gt;\n        &lt;\/DataTemplate&gt;\n    &lt;\/ItemsControl.ItemTemplate&gt;\n&lt;\/ItemsControl&gt;<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-file=\"MainWindowViewModel.cs\" data-lang=\"C#\"><code>for (int i = 1; i &lt; 21; i++)\n{\n    var uc = new SampleUserControlViewModel(_eventAggregator)\n    {\n        Message = string.Format(&quot;This is UserControl of No. {0}&quot;, i)\n    };\n    UserControls.Add(uc);\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">TL; DR<\/h2>\n\n\n\n<p>\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u624b\u52d5\u3067\u8a2d\u5b9a\u3057\u3088\u3046\u3068\u3057\u3066\u3044\u308bUserControl\u306eView\u306e <code>AutoWireViewModel<\/code> \u3092 <code>False<\/code> \u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plane\"><code>&lt;UserControl x:Class=&quot;PrismUserControlTest.Content.Views.SampleUserControl&quot;\n             ...\n             prism:ViewModelLocator.AutoWireViewModel=&quot;False&quot;&gt;<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f55\u304c\u539f\u56e0\u3060\u3063\u305f\u306e\u304b<\/h2>\n\n\n\n<p>\u3059\u3054\u304f\u8a73\u7d30\u306b\u8abf\u67fb\u3057\u305f\u3068\u3044\u3046\u308f\u3051\u3067\u306f\u306a\u3044\u306e\u3067\u3059\u304c\u3001\u3069\u3046\u3082\u3053\u3053\u304c <code>True<\/code> \u3060\u3068VM\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u6301\u3063\u3066\u3044\u3088\u3046\u3068\u3044\u307e\u3044\u3068\u554f\u7b54\u7121\u7528\u3067View\u306b\u7d10\u4ed8\u304fVM\u304c\u751f\u6210\u3055\u308c\u308b\u3089\u3057\u3044\u306e\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u306e\u7d50\u679c<span data-color=\"#fcb900\" style=\"background: linear-gradient(transparent 60%,rgba(252, 185, 0, 0.7) 0);\" class=\"vk_highlighter\">\u30c7\u30d0\u30c3\u30ac\u3067\u30d6\u30ec\u30fc\u30af\u30dd\u30a4\u30f3\u30c8\u5f35\u3063\u3066ObservableCollection\u306e\u4e2d\u8eab\u3092\u898b\u305f\u3089\u8a2d\u5b9a\u3057\u305f\u30d7\u30ed\u30d1\u30c6\u30a3\u3067\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5b58\u5728\u3059\u308b\u306e\u306b\u3001\u306a\u305c\u304bView\u306b\u53cd\u6620\u3055\u308c\u306a\u3044<\/span>\u3068\u3044\u3046\u4e8b\u8c61\u3068\u3057\u3066\u767a\u73fe\u3057\u3066\u3044\u305f\u306e\u3067\u306f\u306a\u3044\u304b\u3068\u63a8\u6e2c\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30b5\u30f3\u30d7\u30eb\u30bd\u30fc\u30b9<\/h2>\n\n\n\n<p>\u5b9f\u9a13\u306e\u305f\u3081\u306b\u4f5c\u3063\u305f\u30bd\u30fc\u30b9\u3092GitHub\u306b\u4e0a\u3052\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u53c2\u8003\u307e\u3067\u306b\u3054\u89a7\u3044\u305f\u3060\u3051\u308c\u3070\u3068\u60f3\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"linkcard\"><div class=\"lkc-external-wrap\"><a class=\"lkc-link no_icon\" href=\"https:\/\/github.com\/step63r\/PrismUserControlTest\" target=\"_blank\" rel=\"external noopener\"><div class=\"lkc-card\"><div class=\"lkc-info\"><div class=\"lkc-favicon\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.google.com\/s2\/favicons?domain=github.com\" alt=\"\" width=\"16\" height=\"16\" \/><\/div><div class=\"lkc-domain\">GitHub<\/div><\/div><div class=\"lkc-content\"><figure class=\"lkc-thumbnail\"><img decoding=\"async\" class=\"lkc-thumbnail-img\" src=\"\/\/blog.minatoproject.com\/wp-content\/uploads\/pz-linkcard\/cache\/d5c4cbd8f897a8944ceca2e6939e2d3a6b51649effd4f3f5c60a70dd6fe857ed.jpeg\" width=\"100px\" height=\"108px\" alt=\"\" \/><\/figure><div class=\"lkc-title\">step63r\/PrismUserControlTest<\/div><div class=\"lkc-url\" title=\"https:\/\/github.com\/step63r\/PrismUserControlTest\">https:\/\/github.com\/step63r\/PrismUserControlTest<\/div><div class=\"lkc-excerpt\">Contribute to step63r\/PrismUserControlTest development by creating an account on GitHub.<\/div><\/div><div class=\"clear\"><\/div><\/div><\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>What is this? WPF\u3067Prism\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3092\u4f7f\u3063\u3066\u3044\u308b\u74b0\u5883\u3067\u3001ItemsControl\u306a\u3093\u304b\u306e\u4e2d\u3067\u8907\u6570\u306e\u30ab\u30b9\u30bf\u30e0UserControl\u3092\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u5909\u66f4\u3057\u3064\u3064\u751f\u6210\u3057\u305f\u3044\u5834\u5408\u3001\u901a\u5e38\u306e\u72b6\u614b\u3060\u3068\u751f\u6210\u5143\uff08\u89aaWi [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1569,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"vkexunit_cta_each_option":"","footnotes":""},"categories":[3,7],"tags":[],"class_list":["post-1418","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c","category-wpf"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=\/wp\/v2\/posts\/1418","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1418"}],"version-history":[{"count":11,"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=\/wp\/v2\/posts\/1418\/revisions"}],"predecessor-version":[{"id":1766,"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=\/wp\/v2\/posts\/1418\/revisions\/1766"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=\/wp\/v2\/media\/1569"}],"wp:attachment":[{"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}