回答編集履歴
1
xaml全文を受けての修正
answer
CHANGED
@@ -1,12 +1,72 @@
|
|
1
|
-
できればxamlの全文を見せていただきたいところですが難しいでしょうか?
|
1
|
+
~~できればxamlの全文を見せていただきたいところですが難しいでしょうか?~~
|
2
|
+
ご対応ありがとうございます。
|
2
3
|
|
3
|
-
ただ、TextBoxでそのような形でBindingできているのであれば、
|
4
|
+
~~ただ、TextBoxでそのような形でBindingできているのであれば、~~
|
4
|
-
ComboBoxでSelectedValueにCategoryIDをBindingすることで実現可能なような気がします。
|
5
|
+
~~ComboBoxでSelectedValueにCategoryIDをBindingすることで実現可能なような気がします。~~
|
5
|
-
下記のサンプルを試していただければと思います。
|
6
|
+
~~下記のサンプルを試していただければと思います。~~
|
6
7
|
|
8
|
+
CollectionViewSourceの動作に自信がありませんが、下記のようにDataContextにpersonViewSourceが
|
9
|
+
設定されているObject下にComboBoxを置く必要があるかと思います。
|
10
|
+
一応手元の環境でpersonViewSourceまで選択したCategoryIDが反映されるところまでは動作確認しました。
|
11
|
+
|
7
12
|
```
|
8
|
-
<
|
9
|
-
|
10
|
-
/
|
13
|
+
<Window x:Class="ComboTest.MainWindow"
|
14
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
15
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
16
|
+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
17
|
+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
18
|
+
xmlns:local="clr-namespace:ComboTest"
|
19
|
+
mc:Ignorable="d"
|
20
|
+
Title="MainWindow" Height="450" Width="572.14" Loaded="Window_Loaded">
|
21
|
+
<Window.Resources>
|
22
|
+
<CollectionViewSource x:Key="personViewSource" d:DesignSource="{d:DesignInstance {x:Type local:Person}, CreateList=True}"/>
|
23
|
+
</Window.Resources>
|
24
|
+
<!--ここに参照を追加-->
|
25
|
+
<Grid DataContext="{StaticResource personViewSource}">
|
26
|
+
<Grid x:Name="grid1" DataContext="{StaticResource personViewSource}" HorizontalAlignment="Left" Margin="302,96,0,0" VerticalAlignment="Top">
|
27
|
+
<Grid.ColumnDefinitions>
|
28
|
+
<ColumnDefinition Width="Auto"/>
|
29
|
+
<ColumnDefinition/>
|
30
|
+
</Grid.ColumnDefinitions>
|
31
|
+
<Grid.RowDefinitions>
|
32
|
+
<RowDefinition Height="Auto"/>
|
33
|
+
</Grid.RowDefinitions>
|
34
|
+
</Grid>
|
35
|
+
<Grid x:Name="grid2" DataContext="{StaticResource personViewSource}" HorizontalAlignment="Left" Margin="127,176,0,0" VerticalAlignment="Top">
|
36
|
+
<Grid.ColumnDefinitions>
|
37
|
+
<ColumnDefinition Width="Auto"/>
|
38
|
+
<ColumnDefinition Width="Auto"/>
|
39
|
+
</Grid.ColumnDefinitions>
|
40
|
+
<Grid.RowDefinitions>
|
41
|
+
<RowDefinition Height="Auto"/>
|
42
|
+
</Grid.RowDefinitions>
|
43
|
+
<Label Content="名前:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="0" VerticalAlignment="Center"/>
|
44
|
+
<TextBox x:Name="名前TextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="0" Text="{Binding 名前, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
|
45
|
+
</Grid>
|
46
|
+
<ComboBox x:Name="comboTest" HorizontalAlignment="Left" Margin="168,55,0,0" VerticalAlignment="Top" Width="120"
|
47
|
+
SelectedValue={Binding CategoryID,UpdateSourceTrigger=PropertyChanged}/>
|
48
|
+
<Grid x:Name="grid3" DataContext="{StaticResource personViewSource}" HorizontalAlignment="Left" Margin="86,140,0,0" VerticalAlignment="Top">
|
49
|
+
<Grid.ColumnDefinitions>
|
50
|
+
<ColumnDefinition Width="Auto"/>
|
51
|
+
<ColumnDefinition Width="Auto"/>
|
52
|
+
</Grid.ColumnDefinitions>
|
53
|
+
<Grid.RowDefinitions>
|
54
|
+
<RowDefinition Height="Auto"/>
|
55
|
+
</Grid.RowDefinitions>
|
56
|
+
<Label Content="Category ID:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="0" VerticalAlignment="Center"/>
|
57
|
+
<TextBox x:Name="categoryIDTextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="0" Text="{Binding CategoryID, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
|
58
|
+
</Grid>
|
59
|
+
<Button Content="登録" HorizontalAlignment="Left" Margin="174,231,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
|
60
|
+
<TextBlock HorizontalAlignment="Left" Margin="298,144,0,0" TextWrapping="Wrap" Text="バインドされている。" VerticalAlignment="Top" Height="23" Width="117"/>
|
61
|
+
<TextBlock HorizontalAlignment="Left" Margin="302,56,0,0" TextWrapping="Wrap" Text="バインドされていない。" VerticalAlignment="Top" Height="23" Width="122"/>
|
11
62
|
|
63
|
+
</Grid>
|
64
|
+
</Window>
|
65
|
+
|
12
|
-
```
|
66
|
+
```
|
67
|
+
|
68
|
+
|
69
|
+
※念のための確認
|
70
|
+
このぐらいの操作であればCollectionViewSourceは不要で、
|
71
|
+
単にWindowのDataContextにPersonを設定すれば動作するように思えますが、
|
72
|
+
ColectionViewSourceを使用している理由はございますか?
|