Serg046
Serg046

Reputation: 1173

MahApps MetroProgressBar does not work inside ControlTemplate

I would like to use MetroProgressBar in my UserControl.

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

It works fine. But now I need to support external content in the user control. So I created a new one "UserControl2" to demo:

<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>

Then I put the both controls to the form:

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

As result I see that UserControl2 does not show Progress Bar. How can I fix it?

MainWindow

Note: In the designer UserControl2 is rendered as expected with progress bar.

Upvotes: 2

Views: 882

Answers (1)

jsanalytics
jsanalytics

Reputation: 13188

In your style for UserControl2, set properties EllipseDiameter and EllipseOffset to some value (default is 4), as shown below:

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>

Upvotes: 2

Related Questions