2016-04-27 17 views
7

Chciałbym utworzyć niestandardowy CommandBar dla części UWP mojego projektu Xamarin.Komenda niestandardowa Xamarin UWP

Chcę zrobić logo na kolor tła. Jedynym sposobem, aby to uzyskać, jest utworzenie pędzla lub siatki, aby zawierał zarówno kolor tła, jak i obraz.

Przeczytałem, że można to zrobić tak;

<Window.Resources> 
    <VisualBrush x:Key="myBrush"> 
     <VisualBrush.Visual> 
      <Grid> 
       <Rectangle Fill="Red" /> 
       <Image Source="troll.png" /> 
      </Grid> 
     </VisualBrush.Visual> 
    </VisualBrush> 
</Window.Resources> 

muszę dodać ten pasek poleceń podczas wykonywania tak:

var _globalAppBar = new CommandBar(); 
_globalAppBar.Background = [Link to above layout] 

Pytania:

  1. Jak lub gdzie mogę dodać to w moim projekcie Xamarin UWP? Dodaj plik XAML?

  2. Jak mogę połączyć podczas pracy z układem? Czy istnieje lepszy sposób to zrobić?

Odpowiedz

1

Najlepiej, by utworzyć nowy styl dla CommandBar i dodać go do słownika zasobów App.xaml

<Application.Resources> 
<Style TargetType="CommandBar"> 
    <Setter Property="Background"> 
    <Setter.Value> 
     <VisualBrush> 
     <VisualBrush.Visual> 
      <Grid> 
      <Rectangle Fill="Red" /> 
      <Image Source="troll.png" /> 
      </Grid> 
     </VisualBrush.Visual> 
     </VisualBrush> 
    </Setter.Value> 
    </Setter> 
</Style> 
</Application.Resources> 

ponieważ styl nie ma klucza, stanie się on niejawny styl CommandBar i dlatego są stosowane do wszystkich instancji CommandBar