0

XAML ハットを使用してボタンのスタイルを設定する方法の例を教えてください。3 つの状態 (ホバー、通常、押された状態) があります。ボタンの領域全体を画像 (3 つの異なる状態ごとに 1 つ) で覆い、テキストを上部に表示し、異なる状態に対して 3 つの異なる色を表示したいと考えています。私はすでにこのようなものを持っています(テキストブロックの色の状態なし)。この時点で私が抱えている問題は、テキストブロックが下のボタンの入力イベントをブロックしていることです (テキストブロックの色の変更も実装していません....

現在のコード:

<DataTemplate x:Name="SubjectItemTemplate">
    <Canvas Width="225" Height="225">
        <Button Canvas.Left="0" Canvas.Top="0"
                Command="{Binding ElementName=LayoutRoot, Path=DataContext.NavigateToUnitsPage}"
                CommandParameter="{Binding}">
            <Button.Template>
                <ControlTemplate>
                    <Grid Background="{Binding LightThemeColor}" Width="205" Height="205">

                        <controls:ImageButton HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,0,0,0"
                                              NormalStateImageSource="{Binding ImageUriNormal}"
                                              HoverStateImageSource="{Binding ImageUriHover}"
                                              PressedStateImageSource="{Binding ImageUriPressed}" Command="{Binding ElementName=LayoutRoot, Path=DataContext.NavigateToUnitsPage}"
                CommandParameter="{Binding}"/>
                        <TextBlock Text="{Binding Name}" FontSize="18" TextWrapping="Wrap" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,168,0,0" />

                    </Grid>
                </ControlTemplate>
            </Button.Template>

        </Button>
    </Canvas>
</DataTemplate>
4

1 に答える 1

0

ImageButtonイベントが で期待どおりに処理されない理由はTextBlockTextBlockが とインラインで配置され、ImageButton内に含まれていないためImageButtonです。これを変更するには、を のTextBlock中に配置する必要がありImageButtonます。

 <controls:ImageButton HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,0,0,0"
      NormalStateImageSource="{Binding ImageUriNormal}"
      HoverStateImageSource="{Binding ImageUriHover}"
      PressedStateImageSource="{Binding ImageUriPressed}" Command="{Binding ElementName=LayoutRoot, Path=DataContext.NavigateToUnitsPage}" CommandParameter="{Binding}" >
      <TextBlock Text="{Binding Name}" FontSize="18" TextWrapping="Wrap" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,168,0,0" />
 </controls:ImageButton>
于 2012-12-18T18:44:28.327 に答える