添加沿我的自定义Progress-Bar移动的标签

时间:2018-02-21 14:00:20

标签: wpf styles progress-bar

我有GridViewColumn.CellTemplate

<GridViewColumn.CellTemplate>
    <DataTemplate>
        <StackPanel Orientation="Horizontal">
              <Grid Margin="-6,0,0,0">
                    <ProgressBar Name="progressBarColumn"
                                 Minimum="0"
                                 Maximum="100"
                                 Value="{Binding Progress, UpdateSourceTrigger=PropertyChanged}" 
                 Style="{StaticResource CustomProgressBar4}"
                                 Width="350"
                                 Margin="0,0,0,0"/>
                    <TextBlock x:Name="fileNameTextBlock"
                               Text="{Binding File}"
                               VerticalAlignment="Center"
                               Margin="10,0,0,0"/>
              </Grid>
          </StackPanel>
    </DataTemplate>
</GridViewColumn.CellTemplate>

在我的Progress-Bar内,而不是显示Percentage我更改它以显示我的绑定文件:

Text="{Binding File}"

我的Style

<Style x:Key="CustomProgressBar4" TargetType="ProgressBar">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ProgressBar" >
                    <Grid x:Name="Root">
                        <Border Name="PART_Track" 
                                CornerRadius="5" 
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding Background}"                                
                                BorderThickness="1"/>
                        <Border Name="PART_Indicator" 
                                CornerRadius="5" 
                                Background="{TemplateBinding Foreground}" 
                                BorderBrush="{TemplateBinding Foreground}" 
                                BorderThickness="1" 
                                HorizontalAlignment="Left" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

所以根据我的Progress值(绑定)填充了我的进度条,我想添加位于Label\TextBlock右侧的简单Progress-Bar并显示我的Progress值。

有任何建议怎么做?

1 个答案:

答案 0 :(得分:0)

只需简单地定义两个Grid列,然后将TextBlock添加到第二列

  <Style TargetType="ProgressBar">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ProgressBar">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Grid x:Name="Root" Grid.Column="0">
                            <Border Name="PART_Track"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding Background}"
                                    BorderThickness="1"
                                    CornerRadius="5" />
                            <Border Name="PART_Indicator"
                                    HorizontalAlignment="Left"
                                    Background="{TemplateBinding Foreground}"
                                    BorderBrush="{TemplateBinding Foreground}"
                                    BorderThickness="1"
                                    CornerRadius="5" />
                        </Grid>
                        <TextBlock Grid.Column="1"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   Text="{Binding Path=Value,RelativeSource={RelativeSource TemplatedParent}}" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>