質問編集履歴
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,7 +38,7 @@
|
|
38
38
|
|
39
39
|
<DataTemplate>
|
40
40
|
|
41
|
-
<TextBox x:Name="B"/>
|
41
|
+
<TextBox x:Name="B" />
|
42
42
|
|
43
43
|
</DataTemplate>
|
44
44
|
|
@@ -53,3 +53,183 @@
|
|
53
53
|
</ListView>
|
54
54
|
|
55
55
|
```
|
56
|
+
|
57
|
+
#追記
|
58
|
+
|
59
|
+
例えば、以下に示したデータを適当に入れて項目を生成しておきます。
|
60
|
+
|
61
|
+
TextBoxに何か入力したら左側の項目1のTextBlockに同じテキストを表示するようにしたいのですがこの記述(ElmentNameでの指定)ではうまくいかないようです。
|
62
|
+
|
63
|
+
よくよく考えれば列ごとに同じNameが設定されるのでできない理由はなんとなくわかるのですが・・。
|
64
|
+
|
65
|
+
いろいろ調べて他にRelativeSourceなど試してみましたがこちらでは対応できないようでした。
|
66
|
+
|
67
|
+
```XAML
|
68
|
+
|
69
|
+
<Grid>
|
70
|
+
|
71
|
+
<Grid.Resources>
|
72
|
+
|
73
|
+
<XmlDataProvider x:Key="test" XPath="/test/item" >
|
74
|
+
|
75
|
+
<x:XData>
|
76
|
+
|
77
|
+
<test xmlns="">
|
78
|
+
|
79
|
+
<item foo="hoge"/>
|
80
|
+
|
81
|
+
<item foo="piyo"/>
|
82
|
+
|
83
|
+
</test>
|
84
|
+
|
85
|
+
</x:XData>
|
86
|
+
|
87
|
+
</XmlDataProvider>
|
88
|
+
|
89
|
+
</Grid.Resources>
|
90
|
+
|
91
|
+
<ListView Height="100" Width="200" ItemsSource="{Binding Source={StaticResource test}}">
|
92
|
+
|
93
|
+
<ListView.View>
|
94
|
+
|
95
|
+
<GridView>
|
96
|
+
|
97
|
+
<GridViewColumn Width="100">
|
98
|
+
|
99
|
+
<GridViewColumnHeader Content="項目1"/>
|
100
|
+
|
101
|
+
<GridViewColumn.CellTemplate>
|
102
|
+
|
103
|
+
<DataTemplate >
|
104
|
+
|
105
|
+
<TextBlock Text="{Binding ElementName=B, Path=Text}"/>
|
106
|
+
|
107
|
+
</DataTemplate>
|
108
|
+
|
109
|
+
</GridViewColumn.CellTemplate>
|
110
|
+
|
111
|
+
</GridViewColumn>
|
112
|
+
|
113
|
+
<GridViewColumn Width="100">
|
114
|
+
|
115
|
+
<GridViewColumnHeader Content="項目2"/>
|
116
|
+
|
117
|
+
<GridViewColumn.CellTemplate>
|
118
|
+
|
119
|
+
<DataTemplate>
|
120
|
+
|
121
|
+
<TextBox x:Name="B" Text="{Binding XPath=@foo, UpdateSourceTrigger=PropertyChanged}"/>
|
122
|
+
|
123
|
+
</DataTemplate>
|
124
|
+
|
125
|
+
</GridViewColumn.CellTemplate>
|
126
|
+
|
127
|
+
</GridViewColumn>
|
128
|
+
|
129
|
+
</GridView>
|
130
|
+
|
131
|
+
</ListView.View>
|
132
|
+
|
133
|
+
</ListView>
|
134
|
+
|
135
|
+
</Grid>
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
```
|
140
|
+
|
141
|
+
偶然↑のコード書いてて気が付いたのですが以下のようにTextBlockに「{Binding XPath=@foo}」を指定すればうまくいきました。
|
142
|
+
|
143
|
+
しかし、StyleやContextMenuなどオブジェクトを指定するようなプロパティの場合その方法ではうまくいかないようでした。
|
144
|
+
|
145
|
+
そもそもXPathでのやり方は何か違う?ような気が・・・、かと言ってElementNameでの指定も無理がありそうですし・・・。
|
146
|
+
|
147
|
+
```XAML
|
148
|
+
|
149
|
+
<Grid>
|
150
|
+
|
151
|
+
<Grid.Resources>
|
152
|
+
|
153
|
+
<XmlDataProvider x:Key="test" XPath="/test/item" >
|
154
|
+
|
155
|
+
<x:XData>
|
156
|
+
|
157
|
+
<test xmlns="">
|
158
|
+
|
159
|
+
<item foo="hoge"/>
|
160
|
+
|
161
|
+
<item foo="piyo"/>
|
162
|
+
|
163
|
+
</test>
|
164
|
+
|
165
|
+
</x:XData>
|
166
|
+
|
167
|
+
</XmlDataProvider>
|
168
|
+
|
169
|
+
<Style TargetType="TextBox" x:Key="c">
|
170
|
+
|
171
|
+
<Setter Property="ContextMenu">
|
172
|
+
|
173
|
+
<Setter.Value>
|
174
|
+
|
175
|
+
<ContextMenu>
|
176
|
+
|
177
|
+
<MenuItem Header="1"/>
|
178
|
+
|
179
|
+
</ContextMenu>
|
180
|
+
|
181
|
+
</Setter.Value>
|
182
|
+
|
183
|
+
</Setter>
|
184
|
+
|
185
|
+
</Style>
|
186
|
+
|
187
|
+
</Grid.Resources>
|
188
|
+
|
189
|
+
<ListView Height="100" Width="200" ItemsSource="{Binding Source={StaticResource test}}">
|
190
|
+
|
191
|
+
<ListView.View>
|
192
|
+
|
193
|
+
<GridView>
|
194
|
+
|
195
|
+
<GridViewColumn Width="100">
|
196
|
+
|
197
|
+
<GridViewColumnHeader Content="項目1"/>
|
198
|
+
|
199
|
+
<GridViewColumn.CellTemplate>
|
200
|
+
|
201
|
+
<DataTemplate >
|
202
|
+
|
203
|
+
<TextBlock Text="{Binding XPath=@foo}" ContextMenu="{Binding ElementName=B, Path=ContextMenu, Mode=OneWay}"/>
|
204
|
+
|
205
|
+
</DataTemplate>
|
206
|
+
|
207
|
+
</GridViewColumn.CellTemplate>
|
208
|
+
|
209
|
+
</GridViewColumn>
|
210
|
+
|
211
|
+
<GridViewColumn Width="100">
|
212
|
+
|
213
|
+
<GridViewColumnHeader Content="項目2"/>
|
214
|
+
|
215
|
+
<GridViewColumn.CellTemplate>
|
216
|
+
|
217
|
+
<DataTemplate>
|
218
|
+
|
219
|
+
<TextBox x:Name="B" Text="{Binding XPath=@foo, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource c}"/>
|
220
|
+
|
221
|
+
</DataTemplate>
|
222
|
+
|
223
|
+
</GridViewColumn.CellTemplate>
|
224
|
+
|
225
|
+
</GridViewColumn>
|
226
|
+
|
227
|
+
</GridView>
|
228
|
+
|
229
|
+
</ListView.View>
|
230
|
+
|
231
|
+
</ListView>
|
232
|
+
|
233
|
+
</Grid>
|
234
|
+
|
235
|
+
```
|