【问题标题】:Problem using OpacityMask (XAML)使用 OpacityMask (XAML) 的问题
【发布时间】:2010-07-08 10:40:29
【问题描述】:

有人可以解释这种 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

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

我该如何解决这个问题?

【问题讨论】:

    标签: wpf silverlight xaml


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2019-05-04
      • 2015-05-07
      • 2011-06-26
      • 2018-06-02
      • 1970-01-01
      • 2016-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多