添加沿着我的自定义进度条移动的标签



我有这个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值(绑定)填充的,我想添加简单的LabelTextBlock,它将位于Progress-Bar的右侧并显示我的Progress值。

有什么建议怎么做吗?

只需定义两个网格列,然后在第二列中添加一个文本块

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

相关内容

  • 没有找到相关文章

最新更新