{"id":553,"date":"2019-12-23T03:27:08","date_gmt":"2019-12-22T18:27:08","guid":{"rendered":"http:\/\/marius.main.jp\/software\/blog\/?p=553"},"modified":"2021-03-14T05:40:46","modified_gmt":"2021-03-13T20:40:46","slug":"post-553","status":"publish","type":"post","link":"https:\/\/todosoft.net\/blog\/?p=553","title":{"rendered":"\u5225\u30b9\u30ec\u30c3\u30c9\u3067\u7de8\u96c6\u3055\u308c\u305f\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092Bind\u3059\u308b"},"content":{"rendered":"\n<p>\u5225\u30b9\u30ec\u30c3\u30c9\u3067\u30a2\u30a4\u30c6\u30e0\u8ffd\u52a0\u7b49\u3092\u884c\u3063\u305f\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092Bind\u3059\u308b\u3068\u3001<br>\u300cSystem.NotSupportedException: &#8216;\u3053\u306e\u578b\u306e CollectionView \u306f\u3001Dispatcher \u30b9\u30ec\u30c3\u30c9\u3068\u306f\u7570\u306a\u308b\u30b9\u30ec\u30c3\u30c9\u304b\u3089\u305d\u306e SourceCollection \u3078\u306e\u5909\u66f4\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u307e\u305b\u3093\u3002&#8217;\u300d<br>\u3068\u3044\u3046\u30a8\u30e9\u30fc\u304c\u51fa\u308b\u3002<br>CollectionSynchronization \u306b\u3066\u3001\u53c2\u52a0\u6307\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">MainWindow.xaml<\/h2>\n\n\n\n<pre class=\"wp-block-luxe-blocks-syntaxhighlighter line-numbers language-csharp\"><code class=\"language-csharp\">&lt;Window x:Class=\"WpfApp18.MainWindow\"\n        xmlns=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation\"\n        xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\"\n        xmlns:d=\"http:\/\/schemas.microsoft.com\/expression\/blend\/2008\"\n        xmlns:mc=\"http:\/\/schemas.openxmlformats.org\/markup-compatibility\/2006\"\n        xmlns:local=\"clr-namespace:WpfApp18\"\n        mc:Ignorable=\"d\"\n        Title=\"MainWindow\" Height=\"450\" Width=\"800\">\n\n    &lt;ListView ItemsSource=\"{Binding arrayString}\" \/>\n\n&lt;\/Window><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">MainWindow.xaml.cs<\/h2>\n\n\n\n<pre class=\"wp-block-luxe-blocks-syntaxhighlighter line-numbers language-csharp\"><code class=\"language-csharp\">using System;\nusing System.Collections.ObjectModel;\nusing System.Threading.Tasks;\nusing System.Windows;\nusing System.Windows.Data;\nusing System.Windows.Threading;\n\nnamespace WpfApp18\n{\n    \/\/\/ &lt;summary>\n    \/\/\/ MainWindow.xaml \u306e\u76f8\u4e92\u4f5c\u7528\u30ed\u30b8\u30c3\u30af\n    \/\/\/ &lt;\/summary>\n    public partial class MainWindow : Window\n    {\n        public ObservableCollection&lt;string> arrayString { get; set; } = new ObservableCollection&lt;string>();\n\n        public MainWindow()\n        {\n            InitializeComponent();\n\n            this.DataContext = this;\n\n            \/\/ \u8907\u6570\u30b9\u30ec\u30c3\u30c9\u3067\u4f7f\u7528\u3055\u308c\u308b\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3078\u306e\u53c2\u52a0\n            BindingOperations.EnableCollectionSynchronization(arrayString, new object());\n\n            DispatcherTimer objTimer = new DispatcherTimer()\n            {\n                Interval = new TimeSpan(0, 0, 1)\n            };\n\n            objTimer.Tick += async (object sender, EventArgs e)=>\n            {\n                await Task.Run(() =>\n                {\n                    \/\/ \u5225\u30b9\u30ec\u30c3\u30c9\u3067\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u306b\u30a2\u30a4\u30c6\u30e0\u3092\u8ffd\u52a0\n                    arrayString.Insert(0, DateTime.Now.ToString());\n                });\n            };\n\n            objTimer.Start();\n        }\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5225\u30b9\u30ec\u30c3\u30c9\u3067\u30a2\u30a4\u30c6\u30e0\u8ffd\u52a0\u7b49\u3092\u884c\u3063\u305f\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092Bind\u3059\u308b\u3068\u3001\u300cSystem.NotSupportedException: &#8216;\u3053\u306e\u578b\u306e CollectionView \u306f\u3001Dispatcher \u30b9\u30ec\u30c3\u30c9\u3068\u306f\u7570 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,20,15],"tags":[32,52],"class_list":["post-553","post","type-post","status-publish","format-standard","hentry","category-c","category-wpf","category-15","tag-bind","tag-52"],"_links":{"self":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=553"}],"version-history":[{"count":3,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/553\/revisions"}],"predecessor-version":[{"id":702,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/553\/revisions\/702"}],"wp:attachment":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}