2010-07-08 46 views
1

有人可以解释此WPF行为吗?使用OpacityMask(XAML)的问题

<Page 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <Grid> 
     <!-- Rounded mask --> 
     <Border Name="mask" VerticalAlignment="Top" Background="Black" CornerRadius="48" Height="400" Width="400" /> 
     <StackPanel> 
      <!-- Use a VisualBrush of 'mask' as the opacity mask --> 
      <StackPanel.OpacityMask> 
       <VisualBrush Visual="{Binding ElementName=mask}" /> 
      </StackPanel.OpacityMask>  
      <Grid> 
       <Border Background="Red" Height="400" Width="400"/> 
       <Border Background="Blue" Height="200" Width="400"/> 
      </Grid> 
      </StackPanel> 

    </Grid> 
</Page> 

正如我所期望的,上面的代码生成以下图像(Kaxaml):

alt text http://robbertdam.nl/share/11.png

当我改变线

<Border Background="Blue" Height="200" Width="400"/> 

<Border Background="Blue" Height="200" Width="600"/> 

图像是如下(没想到):

alt text http://robbertdam.nl/share/12.png

角落都不再圆润!这个问题实际上是一个我在我的软件中遇到的问题的“缩小”例子,它使用了类似的掩码。

我该如何解决这个问题?

回答

1

Stretch="None"添加到视觉画笔。

即使原始视觉的大小是固定的,VisualBrush也可以(并且默认会)拉伸正在显示的视觉图像。