具有 2 种颜色的对角拆分按钮 WPF
Diagonally Split Button with 2 colors WPF
我想知道是否可以在 WPF 中创建一个按对角线分成两半的按钮。另外,是否也可以单独给它们上色?
按钮部分不需要是可点击的,只要我能这样给它们上色,我就能想办法解决这个问题。
我试过渐变,但我无法关闭插值,所以那是不可能的。
An Image of what I am thinking of
当然可以用渐变笔刷完成:
<Button Width="100" Height="100" BorderThickness="2"
Background="Blue" Foreground="Red" BorderBrush="Black">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="{Binding Path=Foreground.Color, RelativeSource={RelativeSource TemplatedParent}}"
Offset="0.49"/>
<GradientStop Color="{Binding Path=BorderBrush.Color, RelativeSource={RelativeSource TemplatedParent}}"
Offset="0.495"/>
<GradientStop Color="{Binding Path=BorderBrush.Color, RelativeSource={RelativeSource TemplatedParent}}"
Offset="0.505"/>
<GradientStop Color="{Binding Path=Background.Color, RelativeSource={RelativeSource TemplatedParent}}"
Offset="0.505"/>
</LinearGradientBrush>
</Border.Background>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
我想知道是否可以在 WPF 中创建一个按对角线分成两半的按钮。另外,是否也可以单独给它们上色? 按钮部分不需要是可点击的,只要我能这样给它们上色,我就能想办法解决这个问题。
我试过渐变,但我无法关闭插值,所以那是不可能的。
An Image of what I am thinking of
当然可以用渐变笔刷完成:
<Button Width="100" Height="100" BorderThickness="2"
Background="Blue" Foreground="Red" BorderBrush="Black">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="{Binding Path=Foreground.Color, RelativeSource={RelativeSource TemplatedParent}}"
Offset="0.49"/>
<GradientStop Color="{Binding Path=BorderBrush.Color, RelativeSource={RelativeSource TemplatedParent}}"
Offset="0.495"/>
<GradientStop Color="{Binding Path=BorderBrush.Color, RelativeSource={RelativeSource TemplatedParent}}"
Offset="0.505"/>
<GradientStop Color="{Binding Path=Background.Color, RelativeSource={RelativeSource TemplatedParent}}"
Offset="0.505"/>
</LinearGradientBrush>
</Border.Background>
</Border>
</ControlTemplate>
</Button.Template>
</Button>