回答編集履歴
3
見直しキャンペーン中
answer
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
> Button問わず、すべての場所でButtonとは違うイベントを発生させたいのでCanvasControlがButtonを覆う事が必要と考えました。
|
2
2
|
|
3
3
|
なるほどボタンあるなしにかかわらず、イベントがほしいわけですね。
|
4
|
-
では`PreviewMouseDown`はどうでしょうか。Clickより先に来てしまうのが難点ですが。
|
4
|
+
では`PreviewMouseDown`はどうでしょうか。`Click`より先に来てしまうのが難点ですが。
|
5
5
|
```xml
|
6
6
|
<Window
|
7
7
|
x:Class="Questions225607.MainWindow"
|
2
見直しキャンペーン中
answer
CHANGED
@@ -1,51 +1,51 @@
|
|
1
|
-
> Button問わず、すべての場所でButtonとは違うイベントを発生させたいのでCanvasControlがButtonを覆う事が必要と考えました。
|
2
|
-
|
3
|
-
なるほどボタンあるなしにかかわらず、イベントがほしいわけですね。
|
4
|
-
では`PreviewMouseDown`はどうでしょうか。Clickより先に来てしまうのが難点ですが。
|
5
|
-
```
|
6
|
-
<Window
|
7
|
-
x:Class="Questions225607.MainWindow"
|
8
|
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
9
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
10
|
-
Width="800"
|
11
|
-
Height="450">
|
12
|
-
<Grid Background="#01FFFFFF" PreviewMouseDown="grid1_PreviewMouseDown">
|
13
|
-
<Button
|
14
|
-
x:Name="button1"
|
15
|
-
Width="75"
|
16
|
-
Margin="34,27,0,0"
|
17
|
-
HorizontalAlignment="Left"
|
18
|
-
VerticalAlignment="Top"
|
19
|
-
Click="button1_Click"
|
20
|
-
Content="Button" />
|
21
|
-
<Button
|
22
|
-
x:Name="button2"
|
23
|
-
Width="75"
|
24
|
-
Margin="134,27,0,0"
|
25
|
-
HorizontalAlignment="Left"
|
26
|
-
VerticalAlignment="Top"
|
27
|
-
Click="button2_Click"
|
28
|
-
Content="Button" />
|
29
|
-
</Grid>
|
30
|
-
</Window>
|
31
|
-
```
|
32
|
-
```cs
|
33
|
-
using System.Diagnostics;
|
34
|
-
using System.Windows;
|
35
|
-
using System.Windows.Input;
|
36
|
-
|
37
|
-
namespace Questions225607
|
38
|
-
{
|
39
|
-
public partial class MainWindow : Window
|
40
|
-
{
|
41
|
-
public MainWindow() => InitializeComponent();
|
42
|
-
|
43
|
-
private void grid1_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
44
|
-
=> Debug.WriteLine($"grid1_PreviewMouseDown:{e.GetPosition(this)}");
|
45
|
-
private void button1_Click(object sender, RoutedEventArgs e)
|
46
|
-
=> Debug.WriteLine("button1_Click");
|
47
|
-
private void button2_Click(object sender, RoutedEventArgs e)
|
48
|
-
=> Debug.WriteLine("button2_Click");
|
49
|
-
}
|
50
|
-
}
|
1
|
+
> Button問わず、すべての場所でButtonとは違うイベントを発生させたいのでCanvasControlがButtonを覆う事が必要と考えました。
|
2
|
+
|
3
|
+
なるほどボタンあるなしにかかわらず、イベントがほしいわけですね。
|
4
|
+
では`PreviewMouseDown`はどうでしょうか。Clickより先に来てしまうのが難点ですが。
|
5
|
+
```xml
|
6
|
+
<Window
|
7
|
+
x:Class="Questions225607.MainWindow"
|
8
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
9
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
10
|
+
Width="800"
|
11
|
+
Height="450">
|
12
|
+
<Grid Background="#01FFFFFF" PreviewMouseDown="grid1_PreviewMouseDown">
|
13
|
+
<Button
|
14
|
+
x:Name="button1"
|
15
|
+
Width="75"
|
16
|
+
Margin="34,27,0,0"
|
17
|
+
HorizontalAlignment="Left"
|
18
|
+
VerticalAlignment="Top"
|
19
|
+
Click="button1_Click"
|
20
|
+
Content="Button" />
|
21
|
+
<Button
|
22
|
+
x:Name="button2"
|
23
|
+
Width="75"
|
24
|
+
Margin="134,27,0,0"
|
25
|
+
HorizontalAlignment="Left"
|
26
|
+
VerticalAlignment="Top"
|
27
|
+
Click="button2_Click"
|
28
|
+
Content="Button" />
|
29
|
+
</Grid>
|
30
|
+
</Window>
|
31
|
+
```
|
32
|
+
```cs
|
33
|
+
using System.Diagnostics;
|
34
|
+
using System.Windows;
|
35
|
+
using System.Windows.Input;
|
36
|
+
|
37
|
+
namespace Questions225607
|
38
|
+
{
|
39
|
+
public partial class MainWindow : Window
|
40
|
+
{
|
41
|
+
public MainWindow() => InitializeComponent();
|
42
|
+
|
43
|
+
private void grid1_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
44
|
+
=> Debug.WriteLine($"grid1_PreviewMouseDown:{e.GetPosition(this)}");
|
45
|
+
private void button1_Click(object sender, RoutedEventArgs e)
|
46
|
+
=> Debug.WriteLine("button1_Click");
|
47
|
+
private void button2_Click(object sender, RoutedEventArgs e)
|
48
|
+
=> Debug.WriteLine("button2_Click");
|
49
|
+
}
|
50
|
+
}
|
51
51
|
```
|
1
e
answer
CHANGED
@@ -41,7 +41,7 @@
|
|
41
41
|
public MainWindow() => InitializeComponent();
|
42
42
|
|
43
43
|
private void grid1_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
44
|
-
=> Debug.WriteLine($"grid1_PreviewMouseDown:{
|
44
|
+
=> Debug.WriteLine($"grid1_PreviewMouseDown:{e.GetPosition(this)}");
|
45
45
|
private void button1_Click(object sender, RoutedEventArgs e)
|
46
46
|
=> Debug.WriteLine("button1_Click");
|
47
47
|
private void button2_Click(object sender, RoutedEventArgs e)
|