ProgressBar as background for DataGridView rows

别来无恙 提交于 2020-01-05 06:50:43

问题


Is it possible to set ProgressBar as background for DataGridView row? Or color only part of the row from left to right? I have rows that represent some dynamically changing data and I need to show that progress somehow. I want to use an entire row background as a progress bar, how can I do that?


回答1:


If you want to use the entire row it might be best to override the default template of the DataGridRow using the DataGrid.RowStyle, then you lay a ProgressBar below the other content, e.g.

<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="{x:Type DataGridRow}">
            <Border x:Name="DGR_Border"
              BorderBrush="{TemplateBinding BorderBrush}"
              BorderThickness="{TemplateBinding BorderThickness}"
              SnapsToDevicePixels="True">
            <Grid>
                <ProgressBar Value="{Binding SomeProperty" Minimum="0" Maximum="100"/>
                <!-- Rest of default template here -->
            </Grid>
        </ControlTemplate>
    </Setter.Value>
</Setter Property="Template">



回答2:


You can use datagrid templated columns to show any kind of control.

<DataGrid ItemsSource="{Binding items}">
                <DataGrid.Columns>
                    <DataGridTemplateColumn>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <ProgressBar></ProgressBar>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                </DataGrid.Columns>
            </DataGrid>


来源:https://stackoverflow.com/questions/7284213/progressbar-as-background-for-datagridview-rows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!