teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

現時点でのコードを記載。

2018/06/12 07:00

投稿

heart_crimson
heart_crimson

スコア15

title CHANGED
File without changes
body CHANGED
@@ -120,4 +120,127 @@
120
120
  - .NET Framework 4.5.1
121
121
 
122
122
  参考にできるサイトでも構いませんので、皆さんの力をお借り出来ればと思います。
123
- どうぞよろしくお願いいたします。
123
+ どうぞよろしくお願いいたします。
124
+
125
+ ### 現在のソースコード
126
+ ```xaml
127
+ <Window x:Class="WpfApplication1.MainWindow"
128
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
129
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
130
+ Title="MainWindow" Height="300" Width="525">
131
+ <Grid>
132
+ <Grid.ColumnDefinitions>
133
+ <ColumnDefinition/>
134
+ <ColumnDefinition/>
135
+ </Grid.ColumnDefinitions>
136
+ <!--右のスクロールを動かす→左のスクロールが同期する、という動作は未実装です。-->
137
+ <!--現在、仮にMouseUpイベントを拾っていますが、これでよいのでしょうか?-->
138
+ <!--ほぼほぼ想定通りの動きをするのですが、どれかItemsをクリックしないと反応してくれないのが心残り…-->
139
+ <ListView Name="LeftListView" Grid.Column="0" MouseUp="LeftListView_MouseUp">
140
+ <ListView.Items>
141
+ <TextBlock Text="a"/>
142
+ <TextBlock Text="b"/>
143
+ <TextBlock Text="c"/>
144
+ <TextBlock Text="d"/>
145
+ <TextBlock Text="e"/>
146
+ <TextBlock Text="f"/>
147
+ <TextBlock Text="g"/>
148
+ <TextBlock Text="h"/>
149
+ <TextBlock Text="i"/>
150
+ <TextBlock Text="j"/>
151
+ <TextBlock Text="k"/>
152
+ <TextBlock Text="l"/>
153
+ <TextBlock Text="m"/>
154
+ <TextBlock Text="n"/>
155
+ <TextBlock Text="o"/>
156
+ <TextBlock Text="p"/>
157
+ <TextBlock Text="q"/>
158
+ <TextBlock Text="r"/>
159
+ <TextBlock Text="s"/>
160
+ <TextBlock Text="t"/>
161
+ <TextBlock Text="u"/>
162
+ <TextBlock Text="v"/>
163
+ <TextBlock Text="w"/>
164
+ <TextBlock Text="x"/>
165
+ <TextBlock Text="y"/>
166
+ <TextBlock Text="z"/>
167
+ </ListView.Items>
168
+ </ListView>
169
+ <ListView Name="RightListView" Grid.Column="1">
170
+ <ListView.Items>
171
+ <TextBlock Text="a"/>
172
+ <TextBlock Text="b"/>
173
+ <TextBlock Text="c"/>
174
+ <TextBlock Text="d"/>
175
+ <TextBlock Text="e"/>
176
+ <TextBlock Text="f"/>
177
+ <TextBlock Text="g"/>
178
+ <TextBlock Text="h"/>
179
+ <TextBlock Text="i"/>
180
+ <TextBlock Text="j"/>
181
+ <TextBlock Text="k"/>
182
+ <TextBlock Text="l"/>
183
+ <TextBlock Text="m"/>
184
+ <TextBlock Text="n"/>
185
+ <TextBlock Text="o"/>
186
+ <TextBlock Text="p"/>
187
+ <TextBlock Text="q"/>
188
+ <TextBlock Text="r"/>
189
+ <TextBlock Text="s"/>
190
+ <TextBlock Text="t"/>
191
+ <TextBlock Text="u"/>
192
+ <TextBlock Text="v"/>
193
+ <TextBlock Text="w"/>
194
+ <TextBlock Text="x"/>
195
+ <TextBlock Text="y"/>
196
+ <TextBlock Text="z"/>
197
+ </ListView.Items>
198
+ </ListView>
199
+ </Grid>
200
+ </Window>
201
+ ```
202
+
203
+ ```C#
204
+ // MainWindow.xaml.cs
205
+ using System;
206
+ using System.Collections.Generic;
207
+ using System.Linq;
208
+ using System.Windows;
209
+ using System.Windows.Automation;
210
+ using System.Windows.Automation.Peers;
211
+ using System.Windows.Automation.Provider;
212
+ using System.Windows.Controls;
213
+ using System.Windows.Media;
214
+
215
+ namespace WpfApplication1
216
+ {
217
+ /// <summary>
218
+ /// MainWindow.xaml の相互作用ロジック
219
+ /// </summary>
220
+ public partial class MainWindow : Window
221
+ {
222
+ public MainWindow()
223
+ {
224
+ InitializeComponent();
225
+ }
226
+
227
+ private void LeftListView_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
228
+ {
229
+ var left = LeftListView;
230
+ var scroll = left.Descendants<ScrollViewer>().FirstOrDefault();
231
+
232
+ scroll.ScrollChanged += scroll_ScrollChanged;
233
+ }
234
+
235
+ private void scroll_ScrollChanged(object sender, ScrollChangedEventArgs e)
236
+ {
237
+ var right = RightListView;
238
+ var scroll = right.Descendants<ScrollViewer>().FirstOrDefault();
239
+
240
+ double scrollValue = e.VerticalOffset;
241
+ scroll.ScrollToVerticalOffset(scrollValue);
242
+ }
243
+ }
244
+ }
245
+
246
+ ```