は、どのように私のボタンのグリッドは、私が絵のように私のボタンの六角イメージを持っているWPF、XAML
で私の六角イメージに合うようにします。私はコーナーの端からクリックを取り除き、画像をクリックしたときにだけクリックされるようにしたい。私はいくつかのソリューションを試してきました。クリック可能なグリッドは常に二乗されています。そのため、ボタンのクリック領域が私の画像よりも大きいのです。
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="LayoutGrid"
SnapsToDevicePixels="true">
<ContentPresenter x:Name="contentPresenter"
Focusable="True"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="0"
IsHitTestVisible="True"
ToolTip="Button">
<ContentPresenter.Content>
<Image Source="/WpfApp3;component/Images/hexagonImage.png"
Stretch="None" />
</ContentPresenter.Content>
</ContentPresenter>
<Label Content="Label"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="60,130,60,51"
Width="180"
Height="40"
HorizontalContentAlignment="Center"
RenderTransformOrigin="0.428,-0.075"
FontSize="18"
FontFamily="Arial Narrow"
IsHitTestVisible="False" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsDefaulted"
Value="true" />
<Trigger Property="IsMouseOver"
Value="true" />
<Trigger Property="IsPressed"
Value="true" />
<Trigger Property="IsEnabled"
Value="false">
<Setter Property="TextElement.Foreground"
TargetName="contentPresenter"
Value="{StaticResource Button.Disabled.Foreground}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
このリンク(http://stackoverflow.com/questions/17532063/custom-shaped-button-in-wpf)のリンクをご覧ください。それはあなたの好みに合わせてボタンを形作るためにControlTemplateを使います。あなたの場合は六角形です。 –
@ivica、六角形のジオメトリ([Clip](https://msdn.microsoft.com/en-us/library/system.windows.uielement.clip(v = vs))を使用してLayoutGridに 'Clip'プロパティを設定してみてください。 110).aspx)) – ASh
私は問題が何かを発見しました。 thoの背景のエッジでさえ透明です。まだそこに残っており、問題があります。私はカスタムコントロン(ボタン)を作っていて、私は自分の写真と同じパスを描き、写真と同じ中心に置いてから、クリック可能で透明な私のパスを設定して、私の絵をクリックできないようにして、問題を解決しました。 –