回答編集履歴

4

見直しキャンペーン中

2023/08/13 08:26

投稿

TN8001
TN8001

スコア9326

test CHANGED
@@ -273,9 +273,9 @@
273
273
  C:\Program Files (x86)\Microsoft SDKs\Expression\Blend.NETFramework\v4.0\Libraries
274
274
  ```
275
275
 
276
- `Microsoft.Expression.Drawing.dll`
276
+ * `Microsoft.Expression.Drawing.dll`
277
- `Microsoft.Expression.Interactions.dll`
277
+ * `Microsoft.Expression.Interactions.dll`
278
- `System.Windows.Interactivity.dll`
278
+ * `System.Windows.Interactivity.dll`
279
279
  の3つを`Ctrl`を押しながらクリック、
280
280
  「追加」ボタンを押し、ファイル選択ダイアログを閉じる。
281
281
  「OK」ボタンを押し、参照マネージャーを閉じる。

3

見直しキャンペーン中

2023/07/25 13:00

投稿

TN8001
TN8001

スコア9326

test CHANGED
@@ -1,10 +1,8 @@
1
- WPFで要素のドラッグ移動には、
1
+ WPFで要素のドラッグ移動には、↓こういうのがあります(ありました?)
2
2
  [MouseDragElementBehavior クラス (Microsoft.Expression.Interactivity.Layout) | Microsoft Docs](https://docs.microsoft.com/ja-jp/previous-versions/visualstudio/design-tools/expression-studio-4/ff726476(v=expression.40))
3
- こういうのがあります(ありました?)
3
+
4
-
5
- 現在`Microsoft`はなかったことにしたい?のか、
4
+ 現在Microsoftはなかったことにしたい?のか)こちらに移行させたいようなのですが元の半分程度の実装しかありません。
6
5
  [MouseDragElementBehavior · microsoft/XamlBehaviorsWpf Wiki](https://github.com/Microsoft/XamlBehaviorsWpf/wiki/MouseDragElementBehavior)
7
- こちらに移行させたいようなのですが、元の半分程度の実装しかありません。
8
6
 
9
7
  しかしまだ入手は可能です。
10
8
  ~~[Download Microsoft Expression Blend 4 Software Development Kit (SDK) for .NET 4 from Official Microsoft Download Center](https://www.microsoft.com/ja-jp/download/details.aspx?id=10801)

2

見直しキャンペーン中

2023/07/25 12:57

投稿

TN8001
TN8001

スコア9326

test CHANGED
@@ -1,577 +1,289 @@
1
1
  WPFで要素のドラッグ移動には、
2
-
3
2
  [MouseDragElementBehavior クラス (Microsoft.Expression.Interactivity.Layout) | Microsoft Docs](https://docs.microsoft.com/ja-jp/previous-versions/visualstudio/design-tools/expression-studio-4/ff726476(v=expression.40))
4
-
5
3
  こういうのがあります(ありました?)
6
4
 
7
-
8
-
9
5
  現在`Microsoft`はなかったことにしたい?のか、
10
-
11
6
  [MouseDragElementBehavior · microsoft/XamlBehaviorsWpf Wiki](https://github.com/Microsoft/XamlBehaviorsWpf/wiki/MouseDragElementBehavior)
12
-
13
7
  こちらに移行させたいようなのですが、元の半分程度の実装しかありません。
14
8
 
15
-
16
-
17
9
  しかしまだ入手は可能です。
18
-
19
- [Download Microsoft Expression Blend 4 Software Development Kit (SDK) for .NET 4 from Official Microsoft Download Center](https://www.microsoft.com/ja-jp/download/details.aspx?id=10801)
10
+ ~~[Download Microsoft Expression Blend 4 Software Development Kit (SDK) for .NET 4 from Official Microsoft Download Center](https://www.microsoft.com/ja-jp/download/details.aspx?id=10801)
20
-
21
- `Blend For Visual Studio`がインストールされていれば、すでに入っているはずです(`Blend For Visual Studio`もまだインストール可能だと思うのですが、2019での入れ方がよくわかりませんでした)
11
+ `Blend For Visual Studio`がインストールされていれば、すでに入っているはずです(`Blend For Visual Studio`もまだインストール可能だと思うのですが、2019での入れ方がよくわかりませんでした)~~
22
-
12
+ [Microsoft Expression Blend SDKのダウンロードリンク - vorfee's Tech Blog](https://vorfee.hatenablog.jp/entry/2023/02/01/000929)
23
-
24
-
25
-
26
-
13
+
27
- ```xaml
14
+ ```xml
28
-
29
15
  <Window
30
-
31
16
  x:Class="Questions304033.MainWindow"
32
-
33
17
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
34
-
35
18
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
36
-
37
19
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
38
-
39
20
  xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"
40
-
41
21
  xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
42
-
43
22
  xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
44
-
45
23
  xmlns:local="clr-namespace:Questions304033"
46
-
47
24
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
48
-
49
25
  Title="MainWindow"
50
-
51
26
  Width="800"
52
-
53
27
  Height="450"
54
-
55
28
  Loaded="Window_Loaded"
56
-
57
29
  mc:Ignorable="d">
58
-
59
30
  <Window.Resources>
60
-
61
31
  <Storyboard x:Key="Storyboard1">
62
-
63
32
  <DoubleAnimationUsingKeyFrames Storyboard.TargetName="regularPolygon" Storyboard.TargetProperty="(UIElement.Opacity)">
64
-
65
33
  <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0" />
66
-
67
34
  </DoubleAnimationUsingKeyFrames>
68
-
69
35
  <DoubleAnimationUsingKeyFrames Storyboard.TargetName="regularPolygon1" Storyboard.TargetProperty="(UIElement.Opacity)">
70
-
71
36
  <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0" />
72
-
73
37
  </DoubleAnimationUsingKeyFrames>
74
-
75
38
  <ColorAnimationUsingKeyFrames Storyboard.TargetName="rectangle" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
76
-
77
39
  <EasingColorKeyFrame KeyTime="0:0:1" Value="Orange" />
78
-
79
40
  </ColorAnimationUsingKeyFrames>
80
-
81
41
  </Storyboard>
82
-
83
42
  </Window.Resources>
84
-
85
43
  <Canvas>
86
-
87
44
  <Button Click="Button_Click" Content="リセット" />
88
-
89
45
  <ed:Callout
90
-
91
46
  x:Name="callout"
92
-
93
47
  Canvas.Left="447"
94
-
95
48
  Canvas.Top="15"
96
-
97
49
  Width="240"
98
-
99
- Height="100"
50
+ Height="100"
100
-
101
51
  AnchorPoint="-0.1,1"
102
-
103
52
  CalloutStyle="Oval"
104
-
105
53
  Content="どこにピッタリはまるかな?"
106
-
107
- Fill="#FFF4F4F5"
54
+ Fill="#FFF4F4F5"
108
-
109
- Stroke="Black"
55
+ Stroke="Black"
110
-
111
56
  StrokeThickness="3" />
112
-
113
- <ed:RegularPolygon
57
+ <ed:RegularPolygon
114
-
115
58
  Canvas.Left="126"
116
-
117
59
  Canvas.Top="270"
118
-
119
60
  Width="120"
120
-
121
61
  Height="120"
122
-
123
- Fill="#FFF4F4F5"
62
+ Fill="#FFF4F4F5"
124
-
125
63
  InnerRadius="1"
126
-
127
64
  PointCount="6"
128
-
129
65
  Stretch="Fill"
130
-
131
- Stroke="Black"
66
+ Stroke="Black"
132
-
133
67
  StrokeThickness="3" />
134
-
135
68
  <Rectangle
136
-
137
69
  x:Name="rectangle"
138
-
139
70
  Canvas.Left="368"
140
-
141
71
  Canvas.Top="280"
142
-
143
72
  Width="100"
144
-
145
- Height="100"
73
+ Height="100"
146
-
147
- Fill="#FFF4F4F5"
74
+ Fill="#FFF4F4F5"
148
-
149
75
  RenderTransformOrigin="0.5,0.5"
150
-
151
- Stroke="Black"
76
+ Stroke="Black"
152
-
153
77
  StrokeThickness="3">
154
-
155
78
  <Rectangle.RenderTransform>
156
-
157
79
  <TransformGroup>
158
-
159
80
  <ScaleTransform />
160
-
161
81
  <SkewTransform AngleX="-26.666" />
162
-
163
82
  <RotateTransform />
164
-
165
83
  <TranslateTransform />
166
-
167
84
  </TransformGroup>
168
-
169
85
  </Rectangle.RenderTransform>
170
-
171
86
  </Rectangle>
172
-
173
- <ed:RegularPolygon
87
+ <ed:RegularPolygon
174
-
175
88
  Canvas.Left="597"
176
-
177
89
  Canvas.Top="282"
178
-
179
90
  Width="120"
180
-
181
- Height="100"
91
+ Height="100"
182
-
183
- Fill="#FFF4F4F5"
92
+ Fill="#FFF4F4F5"
184
-
185
93
  InnerRadius="1"
186
-
187
94
  PointCount="5"
188
-
189
95
  Stretch="Fill"
190
-
191
- Stroke="Black"
96
+ Stroke="Black"
192
-
193
97
  StrokeThickness="3" />
194
98
 
195
-
196
-
197
- <ed:RegularPolygon
99
+ <ed:RegularPolygon
198
-
199
100
  x:Name="regularPolygon"
200
-
201
101
  Canvas.Left="100"
202
-
203
102
  Canvas.Top="70"
204
-
205
103
  Width="100"
206
-
207
- Height="100"
104
+ Height="100"
208
-
209
105
  Fill="Orange"
210
-
211
106
  PointCount="3"
212
-
213
107
  RenderTransformOrigin="0.5,0.5"
214
-
215
- Stroke="Black"
108
+ Stroke="Black"
216
-
217
109
  StrokeThickness="3">
218
-
219
110
  <i:Interaction.Behaviors>
220
-
221
111
  <ei:MouseDragElementBehavior
222
-
223
112
  x:Name="mouseDragElementBehavior"
224
-
225
113
  ConstrainToParentBounds="True"
226
-
227
114
  DragFinished="MouseDragElementBehavior_DragFinished" />
228
-
229
115
  </i:Interaction.Behaviors>
230
-
231
116
  <ed:RegularPolygon.RenderTransform>
232
-
233
117
  <TransformGroup>
234
-
235
118
  <ScaleTransform />
236
-
237
119
  <SkewTransform />
238
-
239
120
  <RotateTransform Angle="180" />
240
-
241
121
  <TranslateTransform />
242
-
243
122
  </TransformGroup>
244
-
245
123
  </ed:RegularPolygon.RenderTransform>
246
-
247
124
  </ed:RegularPolygon>
248
125
 
249
-
250
-
251
- <ed:RegularPolygon
126
+ <ed:RegularPolygon
252
-
253
127
  x:Name="regularPolygon1"
254
-
255
128
  Canvas.Left="200"
256
-
257
129
  Canvas.Top="70"
258
-
259
130
  Width="100"
260
-
261
- Height="100"
131
+ Height="100"
262
-
263
132
  Fill="Orange"
264
-
265
133
  PointCount="3"
266
-
267
- Stroke="Black"
134
+ Stroke="Black"
268
-
269
135
  StrokeThickness="3">
270
-
271
136
  <i:Interaction.Behaviors>
272
-
273
137
  <ei:MouseDragElementBehavior
274
-
275
138
  x:Name="mouseDragElementBehavior1"
276
-
277
139
  ConstrainToParentBounds="True"
278
-
279
140
  DragFinished="mouseDragElementBehavior1_DragFinished" />
280
-
281
141
  </i:Interaction.Behaviors>
282
-
283
142
  <!-- ↓消したらダメ 恐らくMouseDragElementBehaviorがバグっていて挙動が変になる -->
284
-
285
143
  <ed:RegularPolygon.RenderTransform>
286
-
287
144
  <TransformGroup>
288
-
289
145
  <ScaleTransform />
290
-
291
146
  <SkewTransform />
292
-
293
147
  <RotateTransform />
294
-
295
148
  <TranslateTransform />
296
-
297
149
  </TransformGroup>
298
-
299
150
  </ed:RegularPolygon.RenderTransform>
300
-
301
151
  </ed:RegularPolygon>
302
-
303
152
  </Canvas>
304
-
305
153
  </Window>
306
-
307
- ```
154
+ ```
308
-
309
-
310
-
155
+
311
- ```C#
156
+ ```cs
312
-
313
157
  using System;
314
-
315
158
  using System.Windows;
316
-
317
159
  using System.Windows.Input;
318
-
319
160
  using System.Windows.Media;
320
-
321
161
  using System.Windows.Media.Animation;
322
162
 
323
-
324
-
325
163
  namespace Questions304033
326
-
327
164
  {
328
-
329
165
  public partial class MainWindow : Window
330
-
331
166
  {
332
-
333
167
  private Transform transform; // ▼初期位置
334
-
335
168
  private Transform transform1;// ▲初期位置
336
169
 
337
-
338
-
339
170
  public MainWindow() => InitializeComponent();
340
171
 
341
-
342
-
343
172
  private void Window_Loaded(object sender, RoutedEventArgs e)
344
-
345
- {
173
+ {
346
-
347
174
  // 三角の初期位置保存
348
-
349
175
  transform = regularPolygon.RenderTransform;
350
-
351
176
  transform1 = regularPolygon1.RenderTransform;
352
-
353
- }
177
+ }
354
-
355
-
356
178
 
357
179
  private void Button_Click(object sender, RoutedEventArgs e)
358
-
359
- {
180
+ {
360
-
361
181
  // 三角とひし形のアニメーションを止めて元に戻す
362
-
363
182
  var storyboard = FindResource("Storyboard1") as Storyboard;
364
-
365
183
  storyboard.Stop();
366
184
 
367
-
368
-
369
185
  // 三角の当たり判定を復活
370
-
371
186
  regularPolygon.IsHitTestVisible = true;
372
-
373
187
  regularPolygon1.IsHitTestVisible = true;
374
188
 
375
-
376
-
377
189
  // 三角を初期位置に戻す
378
-
379
190
  regularPolygon.RenderTransform = transform;
380
-
381
191
  regularPolygon1.RenderTransform = transform1;
382
-
383
- }
192
+ }
384
-
385
-
386
193
 
387
194
  // ▼ドラッグ終了時
388
-
389
195
  private void MouseDragElementBehavior_DragFinished(object sender, MouseEventArgs e)
390
-
391
- {
196
+ {
392
-
393
197
  var x = mouseDragElementBehavior.X;
394
-
395
198
  var y = mouseDragElementBehavior.Y;
396
199
 
397
-
398
-
399
200
  // 目標座標との差分
400
-
401
201
  var dx = Math.Abs(x - 492); // 注)回転しているためWidth Height分だけ増えてる?
402
-
403
202
  var dy = Math.Abs(y - 380);
404
203
 
405
-
406
-
407
204
  // 十分近ければ。。。
408
-
409
205
  if (dx < 20 && dy < 20)
410
-
411
- {
206
+ {
412
-
413
207
  // 三角を目標座標ピッタリに移動
414
-
415
208
  mouseDragElementBehavior.X = 492;
416
-
417
209
  mouseDragElementBehavior.Y = 380;
418
210
 
419
-
420
-
421
211
  // 三角の当たり判定なくし移動できなくする
422
-
423
212
  regularPolygon.IsHitTestVisible = false;
424
-
425
- }
213
+ }
426
-
427
-
428
214
 
429
215
  // もし三角が2つともはまったらアニメーション開始
430
-
431
216
  if (!regularPolygon.IsHitTestVisible && !regularPolygon1.IsHitTestVisible)
432
-
433
- {
217
+ {
434
-
435
218
  var storyboard = FindResource("Storyboard1") as Storyboard;
436
-
437
219
  storyboard.Begin();
438
-
439
- }
220
+ }
440
-
441
- }
221
+ }
442
-
443
-
444
222
 
445
223
  // ▲ドラッグ終了時
446
-
447
224
  private void mouseDragElementBehavior1_DragFinished(object sender, MouseEventArgs e)
448
-
449
- {
225
+ {
450
-
451
226
  var x = mouseDragElementBehavior1.X;
452
-
453
227
  var y = mouseDragElementBehavior1.Y;
454
228
 
455
-
456
-
457
229
  var dx = Math.Abs(x - 342);
458
-
459
230
  var dy = Math.Abs(y - 282);
460
231
 
461
-
462
-
463
232
  if (dx < 20 && dy < 20)
464
-
465
- {
233
+ {
466
-
467
234
  mouseDragElementBehavior1.X = 342;
468
-
469
235
  mouseDragElementBehavior1.Y = 282;
470
236
 
471
-
472
-
473
237
  regularPolygon1.IsHitTestVisible = false;
474
-
475
- }
238
+ }
476
-
477
-
478
239
 
479
240
  if (!regularPolygon.IsHitTestVisible && !regularPolygon1.IsHitTestVisible)
480
-
481
- {
241
+ {
482
-
483
242
  var sb = FindResource("Storyboard1") as Storyboard;
484
-
485
243
  sb.Begin();
486
-
487
- }
244
+ }
488
-
489
- }
245
+ }
490
-
491
246
  }
492
-
493
247
  }
494
-
495
- ```
248
+ ```
496
-
497
249
  参照の追加で下記の追加が必要です。
498
-
499
- ```
250
+ ```
500
-
501
251
  C:\Program Files (x86)\Microsoft SDKs\Expression\Blend.NETFramework\v4.0\Libraries\Microsoft.Expression.Drawing.dll
502
-
503
252
  C:\Program Files (x86)\Microsoft SDKs\Expression\Blend.NETFramework\v4.0\Libraries\Microsoft.Expression.Interactions.dll
504
-
505
253
  C:\Program Files (x86)\Microsoft SDKs\Expression\Blend.NETFramework\v4.0\Libraries\System.Windows.Interactivity.dll
506
-
507
- ```
254
+ ```
508
-
509
-
510
255
 
511
256
  xamlがごちゃごちゃして難しそうですが、`Blend For Visual Studio`で作成したのでほとんどマウス操作だけで済んでいます。
512
257
 
513
-
514
-
515
258
  ![アプリ画像](9ce0e5a7877391bc94f16d63ea913067.png)
516
259
 
517
-
518
-
519
260
  ---
520
261
 
521
-
522
-
523
262
  追記 回答コードを試す場合の手順
524
263
 
525
-
526
-
527
264
  新規ソリューションを`Questions304033`と名前をつけて作成(場所はどこでもOK)
528
-
529
265
  ![新規ソリューション](9c18c2976595b4fa40a0b6a818398c5e.png)
530
266
 
531
-
532
-
533
267
  「ソリューション エクスプローラー」を開き「参照」を右クリック「参照の追加(R)...」を選択
534
-
535
268
  ![参照の追加](6e5a3ede9738292c636d2031e1151c00.png)
536
269
 
537
-
538
-
539
270
  参照マネージャーが開きます。「参照(E)...」ボタンを押す。
540
-
541
271
  ![参照マネージャー](0c06c081b8a35c740745d31bcab40e21.png)
542
272
 
543
-
544
-
545
273
  ファイル選択ダイアログが開くので↓まで移動し
546
-
547
- ```
274
+ ```
548
-
549
275
  C:\Program Files (x86)\Microsoft SDKs\Expression\Blend.NETFramework\v4.0\Libraries
550
-
551
- ```
276
+ ```
552
-
553
-
554
277
 
555
278
  `Microsoft.Expression.Drawing.dll`
556
-
557
279
  `Microsoft.Expression.Interactions.dll`
558
-
559
280
  `System.Windows.Interactivity.dll`
560
-
561
281
  の3つを`Ctrl`を押しながらクリック、
562
-
563
282
  「追加」ボタンを押し、ファイル選択ダイアログを閉じる。
564
-
565
283
  「OK」ボタンを押し、参照マネージャーを閉じる。
566
-
567
284
  ![ファイル選択ダイアログ](9221c53a71d038ced094ca94dfc9b6e4.png)
568
285
 
569
-
570
-
571
286
  「ソリューション エクスプローラー」の「参照」の中に、選択した3つが増えていれば成功です。
572
-
573
287
  ![参照](faefa3972fc5376debd44622e8e6c945.png)
574
288
 
575
-
576
-
577
289
  `MainWindow.xaml`・`MainWindow.xaml.cs`を、まるごとコピペで書き換えれば実行できます。

1

参照の追加

2020/11/16 02:50

投稿

TN8001
TN8001

スコア9326

test CHANGED
@@ -513,3 +513,65 @@
513
513
 
514
514
 
515
515
  ![アプリ画像](9ce0e5a7877391bc94f16d63ea913067.png)
516
+
517
+
518
+
519
+ ---
520
+
521
+
522
+
523
+ 追記 回答コードを試す場合の手順
524
+
525
+
526
+
527
+ 新規ソリューションを`Questions304033`と名前をつけて作成(場所はどこでもOK)
528
+
529
+ ![新規ソリューション](9c18c2976595b4fa40a0b6a818398c5e.png)
530
+
531
+
532
+
533
+ 「ソリューション エクスプローラー」を開き「参照」を右クリック「参照の追加(R)...」を選択
534
+
535
+ ![参照の追加](6e5a3ede9738292c636d2031e1151c00.png)
536
+
537
+
538
+
539
+ 参照マネージャーが開きます。「参照(E)...」ボタンを押す。
540
+
541
+ ![参照マネージャー](0c06c081b8a35c740745d31bcab40e21.png)
542
+
543
+
544
+
545
+ ファイル選択ダイアログが開くので↓まで移動し
546
+
547
+ ```
548
+
549
+ C:\Program Files (x86)\Microsoft SDKs\Expression\Blend.NETFramework\v4.0\Libraries
550
+
551
+ ```
552
+
553
+
554
+
555
+ `Microsoft.Expression.Drawing.dll`
556
+
557
+ `Microsoft.Expression.Interactions.dll`
558
+
559
+ `System.Windows.Interactivity.dll`
560
+
561
+ の3つを`Ctrl`を押しながらクリック、
562
+
563
+ 「追加」ボタンを押し、ファイル選択ダイアログを閉じる。
564
+
565
+ 「OK」ボタンを押し、参照マネージャーを閉じる。
566
+
567
+ ![ファイル選択ダイアログ](9221c53a71d038ced094ca94dfc9b6e4.png)
568
+
569
+
570
+
571
+ 「ソリューション エクスプローラー」の「参照」の中に、選択した3つが増えていれば成功です。
572
+
573
+ ![参照](faefa3972fc5376debd44622e8e6c945.png)
574
+
575
+
576
+
577
+ `MainWindow.xaml`・`MainWindow.xaml.cs`を、まるごとコピペで書き換えれば実行できます。