2010-09-15 5 views
2

Comment définir l'image backgound d'une grille en C# (code derrière).silverlight grid background image

Merci Sp Puis-je faire quelque chose comme ça?

public ImageSource ImageSourcePin 
{ 
    set { this.DreamTypeImagePin.Background = value; } 
} 

Cela a fonctionné, merci pour votre aide

 public String ImageSourcePin 
    { 
     set { 
      ImageBrush img = new ImageBrush(); 
      img.ImageSource = (ImageSource)new ImageSourceConverter().ConvertFromString(value); 
      DreamTypeImagePin.Background = img; 
     } 
    } 
+0

Si vous souhaitez que XAML soit converti en codeBEA. Tu peux essayer ça. http://xamlt.com/ Cela pourrait être utile. –

Répondre

4

ImageBrush img = new ImageBrush(); img.ImageSource = (ImageSource) nouveau ImageSourceConverter(). ConvertFromString ("Image.jpg"); System.Windows.Controls.Grid g = new System.Windows.Controls.Grid(); g.Background = img;

HTH

11

Essayez d'utiliser un ImageBrush. Placez ceci entre vos étiquettes <Grid> et </Grid>.

<Grid.Background> 
    <ImageBrush ImageSource="Image.jpg"/> 
</Grid.Background> 

Impérativement, vous pouvez écrire ce que:

ImageBrush imgBrush = new ImageBrush(); 
imgBrush.ImageSource = new BitmapImage(new Uri(@"folder\img.jpg", UriKind.Relative)); 
grid.Background = imgBrush;