WPF如何在进度条上显示文本 [英] WPF how to display text on progress bar

查看:105
本文介绍了WPF如何在进度条上显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataGrid,其中一列旨在显示下载百分比.下面是我的代码:

I have a DataGrid, one column is designed to display download percent. Below is my code:

<DataGridTemplateColumn Header="Percent" IsReadOnly="True" Width="*">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <DockPanel>
                <Button Margin="5,0,0,0" DockPanel.Dock="Right" VerticalContentAlignment="Center" Style="{StaticResource BasicButtonStyle}" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.StopButtonClickCommand}" >
                    <Image Height="12" Source="/Client;component/Resources/Images/stop.png" />
                </Button>
                <ProgressBar Value="{Binding Path=Percent, Mode=OneWay}" Minimum="0" Maximum="100" />
                <TextBlock Text="{Binding Path=Percent , StringFormat={}{0}%}" HorizontalAlignment="Center" ></TextBlock>
            </DockPanel>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

我想在进度条上显示文本,同时保持右边的按钮.我应该如何修改我的代码?

I want to display the text on progress bar, at same time keep the button on the right. How should I modify my code?

推荐答案

将ProgressBar和TextBlock放入一个容器(网格)

put ProgressBar and TextBlock in one container (Grid)

<Grid>
    <ProgressBar Value="{Binding Path=Percent, Mode=OneWay}" Minimum="0" Maximum="100" />
    <TextBlock Text="{Binding Path=Percent , StringFormat={}{0}%}" HorizontalAlignment="Center" />
</Grid>

这篇关于WPF如何在进度条上显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆