Ask a questionAsk a question
 

Answerhow do you make progress bar with rounded edges?

  • Wednesday, November 04, 2009 7:28 PMregal deagle Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    how do you make a progress bar with rounded edges like this:

     

    i'm specifically trying to do this with a progressbar, not a slider. thanks

Answers

  • Friday, November 06, 2009 1:28 AMWilliam Han - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    I'm not sure if I understand your requirement.  If you want to have rounded corner progressbar, I believe you can adjust Border.CornerRadius property in progressbar control template.  Please see example below:

    <Window x:Class="RoundedProgressBar.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <LinearGradientBrush x:Key="PressedBrush" StartPoint="0,0" EndPoint="0,1">
                <GradientBrush.GradientStops>
                    <GradientStopCollection>
                        <GradientStop Color="#BBB" Offset="0.0"/>
                        <GradientStop Color="#EEE" Offset="0.1"/>
                        <GradientStop Color="#EEE" Offset="0.9"/>
                        <GradientStop Color="#FFF" Offset="1.0"/>
                    </GradientStopCollection>
                </GradientBrush.GradientStops>
            </LinearGradientBrush>
            <SolidColorBrush x:Key="SolidBorderBrush" Color="#888" />
            <LinearGradientBrush x:Key="DarkBrush" StartPoint="0,0" EndPoint="0,1">
                <GradientBrush.GradientStops>
                    <GradientStopCollection>
                        <GradientStop Color="#FFF" Offset="0.0"/>
                        <GradientStop Color="#AAA" Offset="1.0"/>
                    </GradientStopCollection>
                </GradientBrush.GradientStops>
            </LinearGradientBrush>
            <LinearGradientBrush x:Key="NormalBorderBrush" StartPoint="0,0" EndPoint="0,1">
                <GradientBrush.GradientStops>
                    <GradientStopCollection>
                        <GradientStop Color="#CCC" Offset="0.0"/>
                        <GradientStop Color="#444" Offset="1.0"/>
                    </GradientStopCollection>
                </GradientBrush.GradientStops>
            </LinearGradientBrush>
            <Style x:Key="{x:Type ProgressBar}" TargetType="{x:Type ProgressBar}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ProgressBar}">
                            <Grid MinHeight="14" MinWidth="200">
                                <Border Name="PART_Track" CornerRadius="15" Background="{StaticResource PressedBrush}" BorderBrush="{StaticResource SolidBorderBrush}" BorderThickness="1" />
                                <Border Name="PART_Indicator" CornerRadius="15" Background="{StaticResource DarkBrush}" BorderBrush="{StaticResource NormalBorderBrush}"  BorderThickness="1" HorizontalAlignment="Left" />
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Window.Resources>
        <StackPanel>
            <ProgressBar Width="200" Height="30" Value="80"/>
        </StackPanel>
    </Window>


    William

All Replies

  • Wednesday, November 04, 2009 8:20 PMWilliam Han - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Change ProgressBar control template will do it.  Please see example at http://msdn.microsoft.com/en-us/library/ms750638.aspx
    William
  • Friday, November 06, 2009 12:20 AMregal deagle Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    um, yeah, how do i make a rounded progress bar? i don't see anywhere how it tells me to make a rounded progress bar.
  • Friday, November 06, 2009 1:28 AMWilliam Han - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    I'm not sure if I understand your requirement.  If you want to have rounded corner progressbar, I believe you can adjust Border.CornerRadius property in progressbar control template.  Please see example below:

    <Window x:Class="RoundedProgressBar.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <LinearGradientBrush x:Key="PressedBrush" StartPoint="0,0" EndPoint="0,1">
                <GradientBrush.GradientStops>
                    <GradientStopCollection>
                        <GradientStop Color="#BBB" Offset="0.0"/>
                        <GradientStop Color="#EEE" Offset="0.1"/>
                        <GradientStop Color="#EEE" Offset="0.9"/>
                        <GradientStop Color="#FFF" Offset="1.0"/>
                    </GradientStopCollection>
                </GradientBrush.GradientStops>
            </LinearGradientBrush>
            <SolidColorBrush x:Key="SolidBorderBrush" Color="#888" />
            <LinearGradientBrush x:Key="DarkBrush" StartPoint="0,0" EndPoint="0,1">
                <GradientBrush.GradientStops>
                    <GradientStopCollection>
                        <GradientStop Color="#FFF" Offset="0.0"/>
                        <GradientStop Color="#AAA" Offset="1.0"/>
                    </GradientStopCollection>
                </GradientBrush.GradientStops>
            </LinearGradientBrush>
            <LinearGradientBrush x:Key="NormalBorderBrush" StartPoint="0,0" EndPoint="0,1">
                <GradientBrush.GradientStops>
                    <GradientStopCollection>
                        <GradientStop Color="#CCC" Offset="0.0"/>
                        <GradientStop Color="#444" Offset="1.0"/>
                    </GradientStopCollection>
                </GradientBrush.GradientStops>
            </LinearGradientBrush>
            <Style x:Key="{x:Type ProgressBar}" TargetType="{x:Type ProgressBar}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ProgressBar}">
                            <Grid MinHeight="14" MinWidth="200">
                                <Border Name="PART_Track" CornerRadius="15" Background="{StaticResource PressedBrush}" BorderBrush="{StaticResource SolidBorderBrush}" BorderThickness="1" />
                                <Border Name="PART_Indicator" CornerRadius="15" Background="{StaticResource DarkBrush}" BorderBrush="{StaticResource NormalBorderBrush}"  BorderThickness="1" HorizontalAlignment="Left" />
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Window.Resources>
        <StackPanel>
            <ProgressBar Width="200" Height="30" Value="80"/>
        </StackPanel>
    </Window>


    William