문제

블렌드를 사용하여 표준 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