WPF: progress bar in ListView

I am trying to display information from my ObservableCollection<MyData> in a ListView . MyData has:

 string Name string Location int Progress 

Using a DataBinding , I can display the Name and Location for all elements in the ObservableCollection<MyData> in my column. But how can I add a Progress column with a ProgressBar inside? Progress - percentage.

+7
data-binding listview progress-bar wpf
source share
3 answers
 <ListView ItemsSource="{Binding PersonList}"> <ListView.View> <GridView> <GridViewColumn Width="140" Header="GameName" DisplayMemberBinding="{Binding Name}"/> <GridViewColumn Width="140" Header="Progress"> <GridViewColumn.CellTemplate> <DataTemplate> <ProgressBar Maximum="100" Value="{Binding Progress}"/> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> </ListView> 
+10
source share

Your ListView in XAML:

 <ListView x:Name="DataView"> <ListView.ItemTemplate> <DataTemplate> <StackPanel> <Label Content="{Binding Path=Name}" /> <ProgressBar Height="20" Width="100" Value="{Binding Path=Progress}" /> </StackPanel> </DataTemplate> </ListView.ItemTemplate> </ListView> 

Code for:

 internal class MyData { public string Name { get; set; } public int Progress { get; set; } } ... var items = new ObservableCollection<MyData>(); items.Add(new MyData() { Name = "Some", Progress = 25 }); items.Add(new MyData() { Name = "Another", Progress = 91 }); DataView.ItemsSource = items; 
+5
source share

Just bind the Progress property in MyData with the ProgressBar.Value parameter and set the expected MAX value as ProgressBar.Maximum, e.g. 50 below

 <ProgressBar Maximum="50" Value="{Binding Progress}" .. 
+1
source share

All Articles