質問編集履歴
5
refactor
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,163 +8,9 @@
|
|
8
8
|
|
9
9
|
###前提・実現したいこと
|
10
10
|
|
11
|
-
WPFで
|
11
|
+
WPFでDragDropしたいです。
|
12
12
|
|
13
13
|
|
14
|
-
|
15
|
-
###疑問点
|
16
|
-
|
17
|
-
(1)
|
18
|
-
|
19
|
-
DragDrop.DoDragDrop(textblock, textblock.Text, DragDropEffects.Copy);
|
20
|
-
|
21
|
-
DragDrop.DoDragDropの引数は、DependencyObject, object, DragDropEffectsなのだが、TextBlockをcopyしたい場合は、TextBlockをなにに入れればよいか。DependencyObjectなのか、それともobjectなのか?
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
(2)
|
26
|
-
|
27
|
-
Drag開始時の
|
28
|
-
|
29
|
-
DragDrop.DoDragDrop(textblock, textblock.Text, DragDropEffects.Copy);
|
30
|
-
|
31
|
-
の引数と
|
32
|
-
|
33
|
-
Dropしたときの、
|
34
|
-
|
35
|
-
private void WrapPanel_Drop(object sender, DragEventArgs e) {
|
36
|
-
|
37
|
-
の引数には関係はないのか?
|
38
|
-
|
39
|
-
ないとしたら、senderとeはどこから出てきて何が入っているのか。
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
(3)
|
44
|
-
|
45
|
-
DropしたときにTextBlockを取り出すにはどうしたらよいか。
|
46
|
-
|
47
|
-
下記の実装だとstringを取り出して新規にTextBlockをつくり、貼れると思う。
|
48
|
-
|
49
|
-
でも本当にやりたいのは、もともとのTextBlockをDropすること。
|
50
|
-
|
51
|
-
もともとのTextBlockをDropするにはどうしたらよいか。
|
52
|
-
|
53
|
-
Dropしたデータ(e?)から、TextBlockを取り出したい。
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
###該当のソースコード
|
58
|
-
|
59
|
-
```xaml
|
60
|
-
|
61
|
-
<Window x:Class="WpfApplication1.MainWindow"
|
62
|
-
|
63
|
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
64
|
-
|
65
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
66
|
-
|
67
|
-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
68
|
-
|
69
|
-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
70
|
-
|
71
|
-
xmlns:local="clr-namespace:WpfApplication1"
|
72
|
-
|
73
|
-
mc:Ignorable="d"
|
74
|
-
|
75
|
-
Title="MainWindow" Height="350" Width="525">
|
76
|
-
|
77
|
-
<Grid x:Name="MainGrid">
|
78
|
-
|
79
|
-
<TextBlock x:Name="text" Text="photocaption" Margin="10,100,10,10" MouseDown="TextBlock_MouseDown"/>
|
80
|
-
|
81
|
-
</Grid>
|
82
|
-
|
83
|
-
<WrapPanel x:Name="wrappanel" HorizontalAlignment="Left" Height="274" Margin="309,25,0,0" VerticalAlignment="Top" Width="138" Background="AliceBlue"
|
84
|
-
|
85
|
-
AllowDrop="True"
|
86
|
-
|
87
|
-
PreviewDragOver="WrapPanel_PreviewDragOver"
|
88
|
-
|
89
|
-
Drop="WrapPanel_Drop"
|
90
|
-
|
91
|
-
/>
|
92
|
-
|
93
|
-
</Grid>
|
94
|
-
|
95
|
-
</Window>
|
96
|
-
|
97
|
-
```
|
98
|
-
|
99
|
-
```C#
|
100
|
-
|
101
|
-
using System.Windows;
|
102
|
-
|
103
|
-
using System.Windows.Controls;
|
104
|
-
|
105
|
-
using System.Windows.Input;
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
namespace WpfApplication1 {
|
110
|
-
|
111
|
-
public partial class MainWindow : Window {
|
112
|
-
|
113
|
-
public MainWindow() {
|
114
|
-
|
115
|
-
InitializeComponent();
|
116
|
-
|
117
|
-
}
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e) {
|
122
|
-
|
123
|
-
if (sender.GetType().Equals(typeof(TextBlock))) {
|
124
|
-
|
125
|
-
TextBlock textblock = new TextBlock();
|
126
|
-
|
127
|
-
textblock.Text = ((TextBlock)sender).Text;
|
128
|
-
|
129
|
-
DragDrop.DoDragDrop(textblock, textblock.Text, DragDropEffects.Copy);
|
130
|
-
|
131
|
-
}
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
private void WrapPanel_PreviewDragOver(object sender, DragEventArgs e) {
|
138
|
-
|
139
|
-
e.Effects = DragDropEffects.All;
|
140
|
-
|
141
|
-
e.Handled = true;
|
142
|
-
|
143
|
-
}
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
private void WrapPanel_Drop(object sender, DragEventArgs e) {
|
148
|
-
|
149
|
-
WrapPanel panel = sender as WrapPanel;
|
150
|
-
|
151
|
-
string value = (string)e.Data.GetData(typeof(string));
|
152
|
-
|
153
|
-
TextBox textbox = new TextBox();
|
154
|
-
|
155
|
-
textbox.Text = value;
|
156
|
-
|
157
|
-
panel.Children.Add(textbox);
|
158
|
-
|
159
|
-
}
|
160
|
-
|
161
|
-
}
|
162
|
-
|
163
|
-
}
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
```
|
168
14
|
|
169
15
|
|
170
16
|
|
4
typo
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
###前提・実現したいこと
|
10
10
|
|
11
|
-
WPFでTextBl
|
11
|
+
WPFでTextBlockをDragDropしたいです。
|
12
12
|
|
13
13
|
|
14
14
|
|
3
typo
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
WPFでTextBl
|
1
|
+
WPFでTextBlockをDragDropしたいです。
|
test
CHANGED
File without changes
|
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -36,6 +36,8 @@
|
|
36
36
|
|
37
37
|
の引数には関係はないのか?
|
38
38
|
|
39
|
+
ないとしたら、senderとeはどこから出てきて何が入っているのか。
|
40
|
+
|
39
41
|
|
40
42
|
|
41
43
|
(3)
|
@@ -49,20 +51,6 @@
|
|
49
51
|
もともとのTextBlockをDropするにはどうしたらよいか。
|
50
52
|
|
51
53
|
Dropしたデータ(e?)から、TextBlockを取り出したい。
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
###発生している問題・エラーメッセージ
|
58
|
-
|
59
|
-
DragDrop.DoDragDrop(textblock, textblock.Text, DragDropEffects.Copy);
|
60
|
-
|
61
|
-
//DragDrop.DoDragDrop(sender as TextBlock, textblock.Text, DragDropEffects.Copy);
|
62
|
-
|
63
|
-
//型 'System.NullReferenceException' のハンドルされていない例外が PresentationCore.dll で発生しました
|
64
|
-
|
65
|
-
//追加情報: オブジェクト参照がオブジェクト インスタンスに設定されていません。
|
66
54
|
|
67
55
|
|
68
56
|
|
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -40,22 +40,14 @@
|
|
40
40
|
|
41
41
|
(3)
|
42
42
|
|
43
|
-
private void WrapPanel_PreviewDragOver(object sender, DragEventArgs e) {
|
44
|
-
|
45
|
-
//if (e.Data.GetDataPresent(DataFormats.Text, true)) <-この行は必要か? 必要だとしたらTextBlockのときはDataFormatsをどう書けばよいか?
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
43
|
+
DropしたときにTextBlockを取り出すにはどうしたらよいか。
|
50
|
-
|
44
|
+
|
51
|
-
下記の実装だと
|
45
|
+
下記の実装だとstringを取り出して新規にTextBlockをつくり、貼れると思う。
|
52
46
|
|
53
47
|
でも本当にやりたいのは、もともとのTextBlockをDropすること。
|
54
48
|
|
55
49
|
もともとのTextBlockをDropするにはどうしたらよいか。
|
56
50
|
|
57
|
-
string[] texts = e.Data.GetData(DataFormats.Text) as string[];
|
58
|
-
|
59
51
|
Dropしたデータ(e?)から、TextBlockを取り出したい。
|
60
52
|
|
61
53
|
|
@@ -148,8 +140,6 @@
|
|
148
140
|
|
149
141
|
DragDrop.DoDragDrop(textblock, textblock.Text, DragDropEffects.Copy);
|
150
142
|
|
151
|
-
//DragDrop.DoDragDrop(sender as TextBlock, textblock.Text, DragDropEffects.Copy);
|
152
|
-
|
153
143
|
}
|
154
144
|
|
155
145
|
}
|
@@ -158,14 +148,10 @@
|
|
158
148
|
|
159
149
|
private void WrapPanel_PreviewDragOver(object sender, DragEventArgs e) {
|
160
150
|
|
161
|
-
//if (e.Data.GetDataPresent(DataFormats.Text, true)) {
|
162
|
-
|
163
151
|
e.Effects = DragDropEffects.All;
|
164
152
|
|
165
153
|
e.Handled = true;
|
166
154
|
|
167
|
-
//}
|
168
|
-
|
169
155
|
}
|
170
156
|
|
171
157
|
|
@@ -174,17 +160,13 @@
|
|
174
160
|
|
175
161
|
WrapPanel panel = sender as WrapPanel;
|
176
162
|
|
177
|
-
string
|
163
|
+
string value = (string)e.Data.GetData(typeof(string));
|
178
|
-
|
179
|
-
|
164
|
+
|
180
|
-
|
181
|
-
|
165
|
+
TextBox textbox = new TextBox();
|
182
|
-
|
166
|
+
|
183
|
-
|
167
|
+
textbox.Text = value;
|
184
|
-
|
168
|
+
|
185
|
-
|
169
|
+
panel.Children.Add(textbox);
|
186
|
-
|
187
|
-
}
|
188
170
|
|
189
171
|
}
|
190
172
|
|