2009-06-23 5 views
2

J'écris un pinceau en XAML que je peux utiliser pour peindre l'arrière-plan d'un Grid pour créer une bannière. Il ressemble à ceci:Prévention de la déformation dans l'arrière-plan de XAML Grid lors du redimensionnement

An example of the brush applied to the background of a Grid http://i40.tinypic.com/8wl012.png

Je veux la brosse à « étirer » avec le Grid lorsque le Window redimensionne, mais je ne veux pas le centre des angles à se déformer.

The deformed background brush http://i39.tinypic.com/2nly98p.png

Je ne doivent être en mesure de dessiner les formes en arrière-plan d'un Grid. Comment puis-je éviter la déformation?

Le code que j'ai écrit ressemble à ceci:

<Window x:Class="WpfApplication.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Height="60" Width="300"> 
    <Window.Resources> 
     <DrawingBrush x:Key="GridBackground"> 
      <DrawingBrush.Drawing> 
       <DrawingGroup> 
        <DrawingGroup.Children> 
         <GeometryDrawing Geometry="M0,1 0,0 0.4,0 0.45,0.5 0.4,1Z" Brush="#FF6A00" /> 
         <GeometryDrawing Geometry="M0.6,1 0.55,0.5 0.6,0 1,0 1,1Z" Brush="#FF0000" /> 
        </DrawingGroup.Children> 
       </DrawingGroup> 
      </DrawingBrush.Drawing> 
     </DrawingBrush> 
    </Window.Resources> 
    <Grid Background="{StaticResource GridBackground}"> 
     <TextBlock Foreground="White" VerticalAlignment="Center">Some text</TextBlock> 
    </Grid> 
</Window> 

Répondre

0

Je RENDRAIT deux brosses, l'un ancré à droite, et une gauche ancrée à. Quelque chose comme ceci:

<Grid> 
    <GeometryXXX Geometry="M0,1 0,0 0.4,0 0.45,0.5 0.4,1Z" Width="300" HorizontalAlignment="Left" Brush="#FF6A00"> 
    <GeometryXXX Geometry="M0,1 0,0 0.4,0 0.45,0.5 0.4,1Z" Width="300" HorizontalAlignment="Right" Brush="#FF0000"> 
    <TextBlock Foreground="White" VerticalAlignment="Center">Some text</TextBlock> 
</Grid> 

Je n'ai pas mon compilateur ouvert, et je ne me rappelle pas le nom de l'objet dessin de la géométrie.

L'autre façon de le faire serait de créer un valueconverter, et faire quelque chose comme:

... 
    <GeometryDrawing Geometry="{Binding Width, ValueConverter=LeftAngledThing}" Brush="#FF6A00" /> 
    <GeometryDrawing Geometry="{Binding Width, ValueConverter=LeftAngledThing}" Brush="#FF0000" /> 
... 

Vous devrez rechercher la syntaxe exacte pour savoir comment faire si, comme je ne suis pas souvenez-vous-en maintenant.

+0

Il est important que les formes soient en arrière-plan de la grille. Le seul changement que je souhaite apporter à la grille elle-même consiste à ajouter l'attribut Background. –

Questions connexes