2014-04-23 54 views
2

一直在尋找並試圖讓我的按鈕有不同的選擇區域(比方形)。製作圓形選區並不難,但是這種弧形,我找不到一個好的答案。 我想爲Visual Studio這樣做在Blend 2013年在wpf和C中製作自定義形狀的按鈕#

As you can see on this picture

我當前的代碼是:

<Window 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     x:Class="RoundUI.MainWindow" 
     Title="MainWindow" Height="350" Width="525" 
     AllowsTransparency="True" 
     OpacityMask="White" 
     WindowStyle="None" 
     Background="Transparent"> 
    <Grid MouseLeftButtonDown="Window_MouseLeftButtonDown" MouseMove="Grid_MouseMove"> 
     <Grid.Background> 
      <ImageBrush ImageSource="smileface.png" /> 
     </Grid.Background> 
     <Image x:Name="image" HorizontalAlignment="Left" Height="100" Margin="212,29,0,0" VerticalAlignment="Top" Width="100" Source="nool.png" RenderTransformOrigin="0.5,0.5" MouseDown="Image_MouseDown_1" MouseEnter="Image_MouseEnter_1" MouseLeave="Image_MouseLeave" Stretch="Fill" > 
      <Image.RenderTransform> 
       <TransformGroup> 
        <ScaleTransform/> 
        <SkewTransform/> 
        <RotateTransform Angle="90"/> 
        <TranslateTransform/> 
       </TransformGroup> 
      </Image.RenderTransform> 
      <Image.Clip> 
       <EllipseGeometry Center="50,50" RadiusX="45" RadiusY="45" /> 
      </Image.Clip> 
     </Image> 



     <Image HorizontalAlignment="Left" Height="100" Margin="212,214,0,0" VerticalAlignment="Top" Width="100" MouseDown="Image_MouseDown" Source="nool.png" MouseEnter="Image_MouseEnter_2" MouseLeave="Image_MouseLeave_1" Stretch="Fill" Cursor="IBeam" ToolTip="Hello" /> 
     <Ellipse Height="100" Width="100" Margin="317,156,108,94" MouseEnter="Ellipse_MouseEnter" MouseLeave="Ellipse_MouseLeave" MouseDown="Ellipse_MouseDown"> 
      <Ellipse.Fill> 
       <ImageBrush ImageSource="Arc.png"/> 
      </Ellipse.Fill> 
     </Ellipse> 
     <TextBlock x:Name="infoBlock" HorizontalAlignment="Left" Margin="229,172,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" FontSize="16"/> 
     <TextBlock x:Name="clickBlock" HorizontalAlignment="Left" Margin="354,135,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/> 
     <Image x:Name="close" HorizontalAlignment="Left" Visibility="Hidden" Source="nool.png" Height="52" Margin="376,10,0,0" VerticalAlignment="Top" Width="69" MouseDown="close_MouseDown"/> 

    </Grid> 
</Window> 

我的問題是,我怎樣才能使這個綠地面積只有點擊。這將是很好的,如果它可以是所有形狀的通用代碼。

+2

http://stackoverflow.com/questions/6101823/filled-arcs-in-wpf – Sajeetharan

回答

1

弧線必須是圖像嗎?

假如不是,在WPF做到這一點的方法是創建一個路徑,則可以使用鋼筆工具http://i.stack.imgur.com/IlhYq.png)在Blend做到這一點。

注:如果事情應該是一個按鈕,它通常是一個好主意,將其添加爲控制模板按鈕控制。您可以在Blend中通過添加按鈕並從右鍵菜單中選擇編輯其模板來完成此操作。該模板應該是你想要的按鈕看起來像(路徑/圖像/矩形/文本或更復雜的佈局)的任何元素。然後,而不是使用MouseDown事件,您可以使用按鈕的點擊事件,這通常是一個更好的選擇。 (另外,按鈕支持執行MVVM時的命令)