WPFボタンのコンテンツをグラフィックパスに完全に置き換えるにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/403629

質問

Blendを使用して標準のWPFボタンを分解し、きれいなスタイルのボタンを作成できましたが、ボタンスペースの内部(ボタンの幅と高さ)をパスで埋める方法がわかりません。また、ContentPresenterを指定する必要があるかどうか、またはそれが正しいかどうかもわかりません。私はボタンの中央のテキストの後(通常どおり)にいますが、その後ろにグラフィックパスがあります。

誰も私にこれを達成する方法についてフィードバックをくれますか?スタイルは次のように定義されます。

    <ControlTemplate x:Key="CurvedButton" TargetType="{x:Type Button}">
        <Grid>
            <Path Fill="#ff951c1f" Data="F1 M 64,16 C 64,24 56,31 48,31 L 15,31 C 7,31 0,24 0,16 C 0,7 7,0 15,0 L 48,0 C 56,0 64,7 64,16 Z" />
            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Width="Auto" />
        </Grid>
    </ControlTemplate>

このボタンの使用法は次のとおりです。

<StackPanel>
    <Button Template="{StaticResource CurvedButton}" FontFamily="MS Trebuchet" FontSize="40" Width="200" Height="120" Foreground="Black">XXXXXXXXXXX</Button>
</StackPanel>

すべてが完了すると、曲線の赤いボタンのように見えるはずです。

事前に感謝

ライアン

役に立ちましたか?

解決

探している結果を得るためにできることがいくつかあります。

ビューボックスにパスを配置し、それを伸ばして塗りつぶします:

<ControlTemplate x:Key="CurvedButton" TargetType="{x:Type Button}">
    <Grid>
        <Viewbox Stretch="Fill">
            <Path Fill="#ff951c1f" Data="F1 M 64,16 C 64,24 56,31 48,31 L 15,31 C 7,31 0,24 0,16 C 0,7 7,0 15,0 L 48,0 C 56,0 64,7 64,16 Z" />
        </Viewbox>
        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Width="Auto" />
    </Grid>
</ControlTemplate>

パスの代わりに境界線を使用:

<ControlTemplate x:Key="CurvedButton" TargetType="{x:Type Button}">
    <Grid>
        <Border CornerRadius="40" Background="#ff951c1f">
            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Width="Auto" />
        </Border>
    </Grid>
</ControlTemplate>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top