2012-02-07 61 views
1

我有一個矩形,我動態繪製在一個窗口中。所述窗口具有不透明度設置爲0.4的背景。 我想使矩形內的區域完全透明(請參閱窗口背後的內容)。做了一個矩形完全透明(窗口中的一個洞)WPF

有沒有辦法做到這一點?

這裏是我的窗口的代碼:

<Window x:Class="TakeAScreenzone" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="PloofTAS" Height="355" Width="539" Topmost="True" 
    ResizeMode="NoResize" AllowsTransparency="True" 
    ShowInTaskbar="False" ShowActivated="True" WindowStyle="None" Background="#66FFFFFF" > 
    <Grid Name="Grid1"></Grid> 
</Window> 

這裏我用畫我的矩形(其中GRID1是我窗口的主網格)的代碼:

WorkingRectangle = New Rectangle 
     WorkingRectangle.Stroke = New SolidColorBrush(Colors.Red) 
     WorkingRectangle.StrokeThickness = 1 
     WorkingRectangle.Fill = Nothing 
     WorkingRectangle.HorizontalAlignment = Windows.HorizontalAlignment.Left 
     WorkingRectangle.VerticalAlignment = Windows.VerticalAlignment.Top 
     Grid1.Children.Add(WorkingRectangle) 
+0

窗口是40%的不透明度,或矩形是什麼? – 2012-02-07 18:48:53

+0

窗口的背景顏色。我試圖讓窗口內的快照工具具有相同的渲染。 – 2012-02-07 18:50:29

+0

感謝您的澄清 – 2012-02-07 18:52:44

回答

4

我相信,你可以利用下面的方法(在這裏我創建的窗口中央的矩形孔):

<Window x:Class="WpfApplication1.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="PloofTAS" Height="355" Width="539" Topmost="True" 
ResizeMode="NoResize" AllowsTransparency="True" 
ShowInTaskbar="False" ShowActivated="True" WindowStyle="None" Background="Transparent"> 
    <Grid Name="Grid1"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="*" /> 
      <RowDefinition Height="*" /> 
      <RowDefinition Height="*" /> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="*" /> 
      <ColumnDefinition Width="*" /> 
      <ColumnDefinition Width="*" /> 
     </Grid.ColumnDefinitions> 
     <Rectangle Fill="#66FFFFFF" Grid.Column="0" Grid.RowSpan="3"/> 
     <Rectangle Fill="#66FFFFFF" Grid.Column="2" Grid.RowSpan="3"/> 
     <Rectangle Fill="#66FFFFFF" Grid.Column="1" Grid.Row="0"/> 
     <Rectangle Fill="#66FFFFFF" Grid.Column="1" Grid.Row="2"/> 
     <Rectangle x:Name="workingRectangle" Fill="Transparent" Stroke="Red" Grid.Column="1" Grid.Row="1"/> 
    </Grid> 
</Window> 
0

充分利用內部矩形Opacity Mask

+0

你能更精確嗎?我用我的代碼編輯我的第一篇文章。 我看過這篇文章,但是我沒有找到我要做的工作。 – 2012-02-07 19:07:45

+0

-1:7個單詞不是答案。 – 2012-02-07 19:29:07