質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
button

HTMLで用いる<button>タグです。

WPF

Windows Presentation Foundation (WPF) は、魅力的な外観のユーザー エクスペリエンスを持つ Windows クライアント アプリケーションを作成するための次世代プレゼンテーション システムです

Q&A

解決済

1回答

1046閲覧

WPF タッチパネル用画像ボタンの画像切り替えが遅い

p_qGeff

総合スコア2

button

HTMLで用いる<button>タグです。

WPF

Windows Presentation Foundation (WPF) は、魅力的な外観のユーザー エクスペリエンスを持つ Windows クライアント アプリケーションを作成するための次世代プレゼンテーション システムです

1グッド

0クリップ

投稿2022/12/26 13:17

前提

wpfを始めてから2か月の初心者です。
wpfのカスタムコントロールでタッチパネルで使用する画像ボタンを作っています。
タッチ時とディスエーブル時に画像を変化させます。
マウスでクリックするとすぐに画像が切り替わるのですが、指でタッチすると
画像が切り替わるまでに0.5秒ぐらいかかってしまいます。
wpf visualstudio2022 .netFramework4.8

実現したいこと

指でタッチした場合もマウスでクリックした時と同じように、
タッチした瞬間に画像を切り替えたい。

発生している問題・エラーメッセージ

エラーメッセージ

該当のソースコード


Generic.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MenuDisplay">

<Style TargetType="{x:Type local:OriginalButton}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:OriginalButton}"> <Grid Stylus.IsPressAndHoldEnabled="False"> <Image Name="image" Source="{TemplateBinding EnableImage}"> </Image> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsPressed" Value="True" > <Setter TargetName="image" Property="Source" Value="{Binding ClickImage, RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type local:OriginalButton}}}"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter TargetName="image" Property="Source" Value="{Binding DisableImage, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:OriginalButton}}}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
</ResourceDictionary>

OriginalButton.cs

public class OriginalButton : Button { static OriginalButton() { DefaultStyleKeyProperty.OverrideMetadata(typeof(OriginalButton), new FrameworkPropertyMetadata(typeof(OriginalButton))); } public ImageSource EnableImage { get { return (ImageSource)GetValue(EnableImageProperty); } set { SetValue(EnableImageProperty, value); } } public static readonly DependencyProperty EnableImageProperty = DependencyProperty.Register("EnableImage", typeof(ImageSource), typeof(OriginalButton), new PropertyMetadata(null)); public ImageSource DisableImage { get { return (ImageSource)GetValue(DisableImageProperty); } set { SetValue(DisableImageProperty, value); } } public static readonly DependencyProperty DisableImageProperty = DependencyProperty.Register("DisableImage", typeof(ImageSource), typeof(OriginalButton), new PropertyMetadata(null)); public ImageSource ClickImage { get { return (ImageSource)GetValue(ClickImageProperty); } set { SetValue(ClickImageProperty, value); } } public static readonly DependencyProperty ClickImageProperty = DependencyProperty.Register("ClickImage", typeof(ImageSource), typeof(OriginalButton), new PropertyMetadata(null)); }

MainWindow.xaml

<Window x:Class="MenuDisplay.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:MenuDisplay" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800">
<Grid>
<local:OriginalButton x:Name="MenuButton" Content="OriginalButton"
HorizontalAlignment="Center" VerticalAlignment="Center"
EnableImage="Images\A.png"
ClickImage="Images\B.png"
DisableImage="Images\C.PNG"
/>
</Grid>
</Window>


### 試したこと 当初はマウスクリックで画像が切り替わるのにタッチでは切り替わらなかったのですが、 Stylus.IsPressAndHoldEnabled="False"を追加することでタッチにより画像切り替えが 可能となりました。 しかし、マウスクリック時に比べて明らかにタッチでの画像切り替えが遅いです。 Stylus.IsPressAndHoldEnabled="False"の設定の仕方が悪いのか 根本的にアプローチの仕方が悪いのか分かりません。 ### 補足情報(FW/ツールのバージョンなど) ここにより詳細な情報を記載してください。
TN8001👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

p_qGeff

2022/12/27 01:55

どうもありがとうございます。 Stylus.IsFlicksEnabled="False"を追加して試してみました。 現在2in1のnotepcを使っているのですが、通常のPCとして使用しても動作は改善されませんでした。 しかし、タブレットモードにして動作させると反応速度が半分ぐらいに改善されました。 ハードウェアによって差があるのかなと思います。 https://stackoverflow.com/questions/14812631/wpf-longtouch-interferes-with-touchenter どうもありがとうございました。
TN8001

2022/12/27 03:34

それで十分だという場合は、お手数ですが「自己解決」としてください。 [ヘルプ|質問をした後に自己解決してしまった](https://teratail.com/help#resolve-myself) ほかの方の回答をしばらく待ってもかまいませんが、「受付中」のままの放置はご遠慮ください。
guest

回答1

0

自己解決

TN8001様のコメントで、解決とさせていただきます。
どうもありがとうございました。

投稿2022/12/27 05:44

p_qGeff

総合スコア2

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問