2017-11-29 4 views
-1

bekam ich eine Schaltfläche mit Bildrand in XAML:UWP button border imagebild im code hinter?

 <Button Content="Button" HorizontalAlignment="Left" Height="128" Margin="405,16,0,0" Grid.Row="1" VerticalAlignment="Top" Width="295" Foreground="Red"> 
     <Button.BorderBrush> 
      <ImageBrush Stretch="Fill" ImageSource="Assets/myGraphic.png"/> 
     </Button.BorderBrush> 
    </Button> 

was ist der Code für Code hinter?

mein Code:

Button button = new Button() 
        { 
         FontWeight = FontWeights.Bold, 
         FontSize = 12, 
         --> BorderBrush = ?? // new Imagesource("Assets/myGraphic.png") 
         // Foreground = new SolidColorBrush(Colors.Red), 
         VerticalContentAlignment = VerticalAlignment.Bottom, 
         HorizontalContentAlignment = HorizontalAlignment.Center, 
         Content = "my new Button", 
         Tag = i 
        }; 

Dank für Ihre Hilfe!

Antwort

0

eine ImageBrush der Eigenschaft BorderBrush zuordnen:

var button = new Button 
{ 
    BorderBrush = new ImageBrush(new BitmapImage(new Uri(...))) 
    ... 
}; 
-1

hab es geschafft!

   ImageBrush test1 = new ImageBrush(); 
       test1.ImageSource = new BitmapImage(new Uri("ms-appx:///Assets/myGraphic.png")); 

       Button button = new Button() 
        { 
         FontWeight = FontWeights.Bold, 
         FontSize = 12, 
         BorderBrush = test1, 
         // Foreground = new SolidColorBrush(Colors.Red), 
         VerticalContentAlignment = VerticalAlignment.Bottom, 
         HorizontalContentAlignment = HorizontalAlignment.Center, 
         Content = "my new Button", 
         Tag = i 
        };