【问题标题】:WPF DataGrid Progressbar with Text带有文本的 WPF DataGrid 进度条
【发布时间】:2014-05-21 09:37:36
【问题描述】:

我环顾四周寻找解决问题的方法,但我相信很多可用的解决方案都是针对该问题的。

基本上,我在 Datagrid 单元格中有一个进度条,它可以正常工作。但是,我现在想在 Progressbar 中放置文本以显示实际百分比。 这是怎么做到的?

到目前为止我的代码

        <DataGridTemplateColumn Header="Percentage Downloaded" Width="5*">
           <DataGridTemplateColumn.CellTemplate>
              <DataTemplate>
                 <ProgressBar Value="{Binding Path=PercentageDownloaded, Mode=OneWay}" Minimum="0" Maximum="100" />
              </DataTemplate>
           </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>

为了代表我的努力,我尝试在进度条中使用 tag 属性并使用都失败的文本块。

非常感谢

* 解决方案 *

GiangregorioC 提供的解决方案有效,因为我没有意识到您可以将标签放在 DataGridCellTemplate 中!

【问题讨论】:

    标签: c# wpf datagrid progress-bar


    【解决方案1】:

    您可以将进度条和文本块放在网格内,如下所示:

    <Grid>
        <ProgressBar />
        <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" />
    </Grid>
    

    文本块将出现在进度条上。

    【讨论】:

    • 实际上我大约 5 秒前才看到该代码,但是您可以将 放入 DataGridCellTemplate 中吗?如果我尝试一下可能会更快...
    • 是的,您可以在 DataTemplate 中添加网格。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-18
    • 2011-07-07
    • 1970-01-01
    相关资源
    最近更新 更多