WPF how to display text on progress bar

谁都会走 提交于 2020-01-06 02:35:47

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/49894696/wpf-how-to-display-text-on-progress-bar

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