不久前我们做了一个与您类似的多按钮控件。我们为奇形怪状的按钮创建了“路径”项,为圆形按钮创建了一个“椭圆”(这类似于您的顶部按钮):
<Path x:Name="UpImageButton" Data="M148,156 L99,106 L115,90 L136,79 L159,69 L184,65 L200,63 L224,65 L248,71 L271,82 L288,94 L300,106 L252,157 L246.28,153.03999 L239,148 L223,141 L201,138 L176,139 L160,145 z" Height="95" Margin="98.5,62.5,99.5,0" Stretch="Fill" UseLayoutRounding="False" VerticalAlignment="Top" Style="{StaticResource UpImageButtonNormal}" PointerPressed="UpButton_Pressed" PointerReleased="UpButton_Released" PointerExited="UpButton_Released" />
然后是每个路径的“按下”和“正常”样式:
<Style x:Key="UpImageButtonPress" TargetType="Path">
<Setter Property="Stroke">
<Setter.Value>
<ImageBrush ImageSource="images/button_wheelnav_up_arrow_down.png" />
</Setter.Value>
</Setter>
<Setter Property="Fill">
<Setter.Value>
<ImageBrush ImageSource="images/button_wheelnav_up_arrow_down.png" />
</Setter.Value>
</Setter>
</Style>
<Style x:Key="UpImageButtonNormal" TargetType="Path">
<Setter Property="Stroke">
<Setter.Value>
<ImageBrush ImageSource="images/button_wheelnav_up_arrow_up.png" />
</Setter.Value>
</Setter>
<Setter Property="Fill">
<Setter.Value>
<ImageBrush ImageSource="images/button_wheelnav_up_arrow_up.png" />
</Setter.Value>
</Setter>
</Style>
然后在各种处理程序中可以根据需要切换样式:
private void UpButton_Pressed(object sender, PointerRoutedEventArgs e)
{
UpImageButton.Style = this.Resources["UpImageButtonPress"] as Style;
//command code goes here
}
private void UpButton_Released(object sender, PointerRoutedEventArgs e)
{
UpImageButton.Style = this.Resources["UpImageButtonNormal"] as Style;
}
提示:要在设计器中正确创建 Path 对象,请将背景图像添加到包含所有按钮的网格中,以便在编辑路径时查看它们是否正确围绕奇形图像。它使它变得容易得多。然后,您可以在完成后删除背景图像。