wpf 将 ProgressBar 添加到 DataGrid 列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13253384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 06:06:13  来源:igfitidea点击:

Adding ProgressBar to DataGrid column

c#wpf

提问by hs2d

I have a WPF application where i would like to show a progressbar in a datagrid column. Here's what i have so far:

我有一个 WPF 应用程序,我想在其中显示数据网格列中的进度条。这是我到目前为止所拥有的:

    <DataGrid Name="dgOrders" ItemsSource="{Binding}" AutoGenerateColumns="False" HorizontalGridLinesBrush="#35000000" VerticalGridLinesBrush="#35000000" BorderThickness="1" CanUserAddRows="False" CanUserReorderColumns="False" CanUserResizeRows="False" CanUserSortColumns="False" EnableRowVirtualization="False" IsReadOnly="True" RowHeaderWidth="0">
        <DataGrid.Columns>
            <DataGridTemplateColumn Header="Progress" Width="*" Visibility="Hidden">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <ProgressBar Value="{Binding Path=ProgressValue, Mode=OneWay}" Minimum="0" Maximum="100" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
        </DataGrid.Columns>
    </DataGrid>

This works and i get nice progressbars on every row. Now here comes the part i get confused: i use this datagrid inside a UserControlwhat is then used in a Pagelike this:

这有效,我在每一行都得到了不错的进度条。现在到了我感到困惑的部分:我在一个里面使用了这个数据网格,UserControl然后在Page这样的地方使用:

<Grid>
    <Controls:OrderDataGrid x:Name="cntrlOrderDataGrid"></Controls:OrderDataGrid>
</Grid>

And the pages are loaded from a Frame.

并且页面是从Frame.

The question is how and where i should implement the class and the ProgressValueso it would update my ProgressBarvalue binding.

问题是我应该如何以及在哪里实现这个类,ProgressValue所以它会更新我的ProgressBar值绑定。

采纳答案by Arsen Mkrtchyan

ProgressValue should exists in the ItemsSource that you assign to grid, it is not related if you are using usercontrols and frames or not

ProgressValue 应该存在于您分配给网格的 ItemsSource 中,它与您是否使用用户控件和框架无关

Something like this

像这样的东西

public class SomeVal : INotifyPropertyChanged
{
   public int ProgressValue{...}
}

datagrid.ItemsSource = new [] {new SomeVal()};