質問編集履歴
1
解決後の補足を追加。
title
CHANGED
File without changes
|
body
CHANGED
@@ -59,4 +59,38 @@
|
|
59
59
|
どちらの ItemsSource も同じ静的なコレクションを参照していることによる弊害かと思われますが、仕組みがよくわかりません。
|
60
60
|
参照元は同じでも SelectedItem プロパティはそれぞれが持っているんだから、そこは別々の挙動になると思っていました。
|
61
61
|
|
62
|
-
なぜこのような現象になるのか説明していただけないでしょうか。
|
62
|
+
なぜこのような現象になるのか説明していただけないでしょうか。
|
63
|
+
|
64
|
+
---
|
65
|
+
|
66
|
+
(2017/09/06 追記)
|
67
|
+
解決できました。ありがとうございます。
|
68
|
+
|
69
|
+
回答を参考に CollectionViewSource を使わず、Array を使用することで問題を回避できました。
|
70
|
+
|
71
|
+
```XAML
|
72
|
+
<Window x:Class="WpfApplication1.MainWindow"
|
73
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
74
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
75
|
+
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
76
|
+
Title="MainWindow" Height="350" Width="525">
|
77
|
+
<StackPanel>
|
78
|
+
<StackPanel.Resources>
|
79
|
+
<!--<CollectionViewSource x:Key="collection" Source="{Binding Names}" />-->
|
80
|
+
<x:Array x:Key="array" Type="{x:Type sys:String}">
|
81
|
+
<sys:String>item1</sys:String>
|
82
|
+
<sys:String>item2</sys:String>
|
83
|
+
<sys:String>item3</sys:String>
|
84
|
+
<sys:String>item4</sys:String>
|
85
|
+
</x:Array>
|
86
|
+
</StackPanel.Resources>
|
87
|
+
|
88
|
+
<ComboBox x:Name="combobox1" ItemsSource="{Binding Source={StaticResource array}}" />
|
89
|
+
<ComboBox x:Name="combobox2" ItemsSource="{Binding Source={StaticResource array}}" />
|
90
|
+
<TextBlock Text="{Binding SelectedItem, ElementName=combobox1}" />
|
91
|
+
</StackPanel>
|
92
|
+
</Window>
|
93
|
+
|
94
|
+
```
|
95
|
+
|
96
|
+
また、ComboBox.IsSynchronizedWithCurrentItem プロパティを利用することでも問題を回避できました。
|