WPFのボタンに問題があります。
私は多くのページと相対ボタン(> 50)を持つGUIを開発しています。
GUIはタッチスクリーンディスプレイで使用されるはずなので、スマートフォンアプリのどのボタンと同様に、各ボタンには2つのグラフィックス状態が押されていて正常です(ホバリング状態はありません)。関連するC#ファイルC#WPF - 2つの状態ボタンの問題。 (タッチイベント付きのクリックイベント)
private void buttonImageDown(object sender, RoutedEventArgs e)
{
Button button = sender as Button;
button.Content = new Image {
Source = new BitmapImage(new Uri(button.Tag + "")),
VerticalAlignment = VerticalAlignment.Center,
Stretch = Stretch.Uniform
};
}
private void buttonImageUp(object sender, RoutedEventArgs e)
{
Button button = sender as Button;
button.Content = new Image {
Source = new BitmapImage(new Uri(button.Uid)),
VerticalAlignment = VerticalAlignment.Center,
Stretch = Stretch.Uniform
};
}
これを内部
<Button
Uid=".../image_up.png"
Tag=".../image_down.png"
Style="{StaticResource flatButtonStyle}"
TouchLeave="buttonImageUp"
TouchDown="buttonImageDown"
Click="clickEvent"
ClickMode="Press"
>
<Button.Background>
<ImageBrush ImageSource=".../image_up.png" Stretch="Uniform"/>
</Button.Background>
</Button>
ページの一つで
リソースファイル
<Application.Resources>
<Style x:Key="flatButtonStyle" TargetType="Button">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border"
Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Left" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
:現在、私はここに、このソリューションを使用してい
implementatinには多くの問題があります:
あたり2時間をC#の機能を実行するために持っているので、私はC#関数に私がする必要があるたびにコピーする必要がUIDを使用して
遅い応答タグを付けることはできません
新しいページのボタンを使用する
しかし実際の問題は、ボタンが押されたときにclickEventが起動しない理由がわからないことです。また、一部のコンピュータではclickEventは最初の3〜 touchDonwとtouchLeaveの5倍は...
は
(Iは、.NET 4.6.1しかし4.5.2及び4.7と同じ動作を使用している)と思うC#の成分を除去し、ボタンの画像(ソース)を変更することが可能ですちょうどXAMLで、しかし私はしばらく探して、私は何も見つけることができません。
誰かお手伝いできますか?
<Style x:Key="flatButtonStyle" TargetType="{x:Type Button}">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Padding="{TemplateBinding Padding}">
<ContentPresenter TextBlock.Foreground="{TemplateBinding Foreground}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<!-- Setters to style disabled state -->
</Trigger>
<Trigger Property="IsPressed" Value="True">
<!-- Setters to style pressed state -->
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
あなたがあなた自身のスタイルを適用するために持っていて、関連propetiesに触れIsPressedを変更する必要がありますが、これはトリックを行う必要がありpossiblityがある:
[ToggleButton](https://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.togglebutton(v = vs.110).aspx)をエミュレートしようとしていますか? – icebat
イメージを設定するためにスタイルトリガーでこれを行うことはできませんか? UidとTagの問題は何ですか? –
@icebatはいですが、C#を使用することはあまり効率的ではありません。 – xSanciopanzax