2017-07-04 4 views
2

Ich möchte MetroProgressBar in meinem UserControl verwenden.MahApps MetroProgressBar funktioniert nicht in ControlTemplate

<UserControl x:Class="WpfApplication7.UserControl1"> 
    <StackPanel Background="#ccc"> 
     <controls:MetroProgressBar IsIndeterminate="True"/> 
    </StackPanel> 
</UserControl> 

Es funktioniert gut. Aber jetzt muss ich externen Inhalt in der Benutzerkontrolle unterstützen. Also habe ich ein neues "UserControl2" zu Demo:

<StackPanel> 
     <local:UserControl1 Background="#ccc"/> 
     <local:UserControl2 Background="#ccc" Margin="0,6,0,0"/> 
</StackPanel> 

Als Ergebnis sehe ich, dass UserControl2 nicht Progress Bar besagen:

<UserControl x:Class="WpfApplication7.UserControl2"> 
    <UserControl.Resources> 
     <Style TargetType="{x:Type local:UserControl2}"> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="{x:Type local:UserControl2}"> 
         <StackPanel Background="#ccc"> 
          <controls:MetroProgressBar IsIndeterminate="True"/> 
          <!--<ContentPresenter/>--> 
         </StackPanel> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </UserControl.Resources> 
</UserControl> 

Dann habe ich die beiden Kontrollen in die Form zu bringen. Wie kann ich es beheben?

MainWindow

Hinweis: Im Designer UserControl2 gemacht wird, wie mit Fortschrittsbalken erwartet.

+2

Dies wird behoben und wird in v1 verfügbar sein. 6.0. Es ist jetzt auch mit der neuesten Pre-Release-Version, die auch bei NuGet erhältlich ist, testbar. – punker76

+1

@ punker76 Vielen Dank! – Serg046

Antwort

1

In Stil für UserControl2, Satz Eigenschaften EllipseDiameter und EllipseOffset auf einem bestimmten Wert (Standard ist 4), wie unten dargestellt:

enter image description here

<Style TargetType="{x:Type local:UserControl2}"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type local:UserControl2}"> 
        <StackPanel Background="#ccc"> 
         <controls:MetroProgressBar EllipseDiameter="12" 
                EllipseOffset="12" 
                IsIndeterminate="True"/> 
         <!--<ContentPresenter/>--> 
        </StackPanel> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
+2

Dies ist jetzt behoben und wird in v1.6.0 verfügbar sein. Es ist jetzt auch mit der neuesten Pre-Release-Version, die auch bei NuGet erhältlich ist, testbar. – punker76