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

質問編集履歴

6

一部(長押し)解決のため、追記

2019/09/12 00:29

投稿

tride
tride

スコア68

title CHANGED
@@ -1,1 +1,1 @@
1
- WPFでタッチ(クリック)の長押しできる画像ボタンの作り方
1
+ WPFでタッチ(クリック)のできる画像ボタンの作り方
body CHANGED
@@ -14,6 +14,10 @@
14
14
  追記:
15
15
  現状、ボタンをタッチした際、ImageSource_2(image02.png)が長押しに関わらず一瞬で終わってしまいますので、この解決方法が知りたいです。
16
16
 
17
+ 追記:
18
+ タップ長押しについてはMainWindows.xamlに以下を追記して対応できました。
19
+ 現在無効時の仕方で詰まっております。
20
+ Stylus.IsPressAndHoldEnabled="False"
17
21
 
18
22
  環境:
19
23
  IDE:VisualStudio 2019
@@ -39,7 +43,8 @@
39
43
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
40
44
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
41
45
  xmlns:local="clr-namespace:WpfButtonTest03"
42
- Title="MainWindow" Height="450" Width="800">
46
+ Title="MainWindow" Height="450" Width="800"
47
+ Stylus.IsPressAndHoldEnabled="False">
43
48
 
44
49
  <Window.Resources>
45
50
  <ResourceDictionary>

5

質問タイトルの修正

2019/09/12 00:28

投稿

tride
tride

スコア68

title CHANGED
@@ -1,1 +1,1 @@
1
- WPFでタッチ(クリック)のできる画像ボタンの作り方(Xamlからのパスの指定)
1
+ WPFでタッチ(クリック)の長押しできる画像ボタンの作り方
body CHANGED
@@ -11,7 +11,10 @@
11
11
  追記:
12
12
  書き込んで直後にパス指定の仕方が分かったので、そこだけ訂正します。
13
13
 
14
+ 追記:
15
+ 現状、ボタンをタッチした際、ImageSource_2(image02.png)が長押しに関わらず一瞬で終わってしまいますので、この解決方法が知りたいです。
14
16
 
17
+
15
18
  環境:
16
19
  IDE:VisualStudio 2019
17
20
  形式:WPF

4

誤記修正

2019/09/11 08:09

投稿

tride
tride

スコア68

title CHANGED
File without changes
body CHANGED
@@ -67,7 +67,7 @@
67
67
  <ControlTemplate x:Key="TemplateTestButton" TargetType="{x:Type Button}">
68
68
  <Border x:Name="border" BorderThickness="0" BorderBrush="Transparent" CornerRadius="200">
69
69
  <Border.Background>
70
- <ImageBrush ImageSource="{StaticResource ImageSource_2}"/>
70
+ <ImageBrush ImageSource="{StaticResource ImageSource_1}"/>
71
71
  </Border.Background>
72
72
  <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
73
73
  </Border>
@@ -75,7 +75,7 @@
75
75
  <Trigger Property="IsPressed" Value="True">
76
76
  <Setter TargetName="border" Property="Background" >
77
77
  <Setter.Value>
78
- <ImageBrush ImageSource="{StaticResource ImageSource_1}" />
78
+ <ImageBrush ImageSource="{StaticResource ImageSource_2}" />
79
79
  </Setter.Value>
80
80
  </Setter>
81
81
  </Trigger>

3

画像のファイル指定部分のコードに入力漏れがあったので追記しました

2019/09/11 08:07

投稿

tride
tride

スコア68

title CHANGED
File without changes
body CHANGED
@@ -61,12 +61,13 @@
61
61
  <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
62
62
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
63
63
  <BitmapImage x:Key="ImageSource_1" UriSource="pack://application:,,,/Resources/Images/Image01.png" />
64
+ <BitmapImage x:Key="ImageSource_2"
65
+ UriSource="pack://application:,,,/Resources/Images/Image02.png" />
64
66
 
65
-
66
67
  <ControlTemplate x:Key="TemplateTestButton" TargetType="{x:Type Button}">
67
68
  <Border x:Name="border" BorderThickness="0" BorderBrush="Transparent" CornerRadius="200">
68
69
  <Border.Background>
69
- <ImageBrush ImageSource="{StaticResource ImageSource_1}"/>
70
+ <ImageBrush ImageSource="{StaticResource ImageSource_2}"/>
70
71
  </Border.Background>
71
72
  <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
72
73
  </Border>

2

質問一部を訂正

2019/09/11 07:22

投稿

tride
tride

スコア68

title CHANGED
File without changes
body CHANGED
@@ -1,12 +1,17 @@
1
1
  WPFにてタッチ(クリック含む)画像ボタンの作り方に苦戦しております。
2
2
 
3
3
  内容としてはResouceDictionaryのButton.xamlのControlTemplate.Triggersでボタン背景を変えて実現しようかと思ったのですが、うまくできずに行き詰っております。
4
- 特に行き詰っているのは、画像ビルドアクションをResourceにした画像をXamlから指定する事と、タッチイベントをXaml上でどうすれば実現できるのかというところです。
4
+ 特に行き詰っているのは、~~画像ビルドアクションをResourceにした画像をXamlから指定する事~~と、タッチイベントをXaml上でどうすれば実現できるのかというところです。
5
5
  いろいろ試した結果、下のところで止まっております。
6
6
 
7
7
  画像について、全てのビルドアクションはResourceになっております。
8
- 出ているエラーは「パスC:ProguramFiles(x86)\<省略>\Common7\IDE\Resouces\Images\Image01.pngの一部は見つかりませんでした」になっています。
8
+ ~~出ているエラーは「パスC:ProguramFiles(x86)\<省略>\Common7\IDE\Resouces\Images\Image01.pngの一部は見つかりませんでした」になっています。~~
9
9
 
10
+
11
+ 追記:
12
+ 書き込んで直後にパス指定の仕方が分かったので、そこだけ訂正します。
13
+
14
+
10
15
  環境:
11
16
  IDE:VisualStudio 2019
12
17
  形式:WPF
@@ -55,7 +60,7 @@
55
60
  <!-- Button.xaml -->
56
61
  <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
57
62
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
58
- <BitmapImage x:Key="ImageSource_1" UriSource="./Resources/Images/Image01.png" />
63
+ <BitmapImage x:Key="ImageSource_1" UriSource="pack://application:,,,/Resources/Images/Image01.png" />
59
64
 
60
65
 
61
66
  <ControlTemplate x:Key="TemplateTestButton" TargetType="{x:Type Button}">

1

エラー内容を記載

2019/09/11 06:54

投稿

tride
tride

スコア68

title CHANGED
@@ -1,1 +1,1 @@
1
- WPFでタッチ(クリック)のできる画像ボタンの作り方
1
+ WPFでタッチ(クリック)のできる画像ボタンの作り方(Xamlからのパスの指定)
body CHANGED
@@ -4,7 +4,8 @@
4
4
  特に行き詰っているのは、画像ビルドアクションをResourceにした画像をXamlから指定する事と、タッチイベントをXaml上でどうすれば実現できるのかというところです。
5
5
  いろいろ試した結果、下のところで止まっております。
6
6
 
7
- 、全ての画像のビルドアクションはResourceになっております。
7
+ 画像について、全てのビルドアクションはResourceになっております。
8
+ 出ているエラーは「パスC:ProguramFiles(x86)\<省略>\Common7\IDE\Resouces\Images\Image01.pngの一部は見つかりませんでした」になっています。
8
9
 
9
10
  環境:
10
11
  IDE:VisualStudio 2019