2010-07-08 2 views
1

Quelqu'un peut-il expliquer ce comportement de WPF?Problème lors de l'utilisation d'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> 

Comme j'attendre, le code ci-dessus génère l'image suivante (Kaxaml):

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

Quand je change la ligne

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

dans

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

l'image est la suivante (ne s'attendait pas):

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

Les coins ne sont pas arrondis plus! Cette question est en fait un exemple «réduit» d'un problème que je rencontre dans mon logiciel, qui utilise des masques similaires.

Comment puis-je contourner le problème?

Répondre

1

Ajoutez Stretch="None" au pinceau visuel.

VisualBrush peut (et par défaut va) étirer l'image du visuel qu'il affiche même si la taille du visuel d'origine est fixe.

Questions connexes