2011-07-28 62 views
1

我有一個用戶控件是45x45(硬編碼大小 - 它是網格項目的一部分)。當某個屬性有一個值時,我想在右上角顯示一個「剪輯」來指示它。可見性本身很容易實現,但是我的Rectangle超出了控件的範圍,並與其他控件重疊。我嘗試使用「ClipToBounds」屬性,但它沒有做任何事情。當我將其添加到總體控件時,剪輯完美運行,但我對主矩形(填充單元格)的懸停效果停止工作。WPF剪輯矩形

任何想法?我相信這很容易做到,但對於WPF來說還是個新鮮事物(並且對於幾何體而言可怕 - 因此不使用多邊形)我有點失落。

以下是完整的標記:

<Grid>   
    <Rectangle x:Name="MainRectangle" Fill="{Binding Background}" Opacity="0" MouseEnter="MainRectangle_MouseEnter" MouseLeave="MainRectangle_MouseLeave"> 
     <Rectangle.Triggers> 
      <EventTrigger RoutedEvent="Rectangle.MouseEnter"> 
       <BeginStoryboard> 
        <Storyboard> 
         <DoubleAnimation Storyboard.TargetProperty="Opacity" From="0.0" To="0.8" Duration="0:0:0.33" AutoReverse="False" /> 
        </Storyboard> 
       </BeginStoryboard> 
      </EventTrigger> 
      <EventTrigger RoutedEvent="Rectangle.MouseLeave"> 
       <BeginStoryboard> 
        <Storyboard> 
         <DoubleAnimation Storyboard.TargetProperty="Opacity" From="0.8" To="0.0" Duration="0:0:0.33" AutoReverse="False" /> 
        </Storyboard> 
       </BeginStoryboard> 
      </EventTrigger> 
     </Rectangle.Triggers> 
    </Rectangle> 
    <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding VisualCount}" /> 
    <Rectangle Fill="Black" HorizontalAlignment="Right" Height="20" Margin="0,-14,-20,0" Stroke="Black" VerticalAlignment="Top" Width="20" Visibility="{Binding HasNotes}"> 
     <Rectangle.RenderTransform> 
      <RotateTransform CenterX="0" CenterY="0" Angle="45" /> 
     </Rectangle.RenderTransform> 
    </Rectangle> 
</Grid> 

回答

1

這裏是簡單的路徑:

<Path Fill="Black" HorizontalAlignment="Right" Visibility="{Binding HasNotes}"> 
    <Path.Data> 
     <PathGeometry> 
      <PathFigure StartPoint="0,0"> 
       <LineSegment Point="14,0"/> 
       <LineSegment Point="14,14"/> 
      </PathFigure> 
     </PathGeometry> 
    </Path.Data> 
</Path> 
+0

完美。我懷疑自己曾經想過這件事。謝謝! – RubyHaus

+0

這並不難,只需要嘗試! –