使用OpacityMask(XAML)的问题

时间:2010-07-08 10:40:30

标签: wpf silverlight xaml

有人可以解释这个WPF行为吗?

<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 个答案:

答案 0 :(得分:1)

Stretch="None"添加到可视笔刷。

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