WPF - Get ProgressBar Template to Stretch to fit Parent Grid

  • Thread starter Thread starter Wonko the Sane
  • Start date Start date
W

Wonko the Sane

Hello,

I have defined a control template for a progress bar. This progress bar
sits in a grid column with the width set to *. How do I get the progress bar
to fill in the entire space of that grid column (like it does if a
non-templated progress bar is used)?

Thanks,
WtS
 
Hi WtS,

I think this will depend on how is the control template defined. Would you
please show us the content of the <ControlTemplate> element for the
ProgressBar? Thanks.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Would you please show us the content of the said:
element for the ProgressBar?

Here is the entire Style that defines the Progress Bar:

<Style TargetType="{x:Type ProgressBar}">
<Setter Property="Height" Value="26" />
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Margin" Value="5,10,5,10" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ProgressBar}">
<Grid Background="Transparent" Width="{Binding
RelativeSource={RelativeSource TemplatedParent}, Path=Width}">
<Border Name="PART_Track" CornerRadius="4" BorderThickness="1"
Background="{StaticResource ProgressBarBackground}"
BorderBrush="{StaticResource
ProgressBarSolidBorderBrush}" />
<Border Name="PART_Indicator" CornerRadius="4"
BorderThickness="1" HorizontalAlignment="Left"
Background="{StaticResource ProgressBarForeground}"
BorderBrush="{StaticResource
ProgressBarNormalBorderBrush}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
 
Hi,

To make the control auto fit width within the container, you have to use
"Stretch" for the HorizontalAlignment property. Therefore you cannot use

<Setter Property="HorizontalAlignment" Value="Center"/>


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top