• C# Подскажите элемент для списка

    @Gilga
    f9bb109a5ef199eeba845854e18afbce.jpg
    MainWindow.xaml
    <Window
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="WpfApplication1.MainWindow"
            Title="MainWindow" Height="350" Width="525">
    	<Grid>
    		<ListView ItemsSource="{Binding ExampleList}">
    			<ListView.Resources>
    				<DataTemplate x:Key="DataTemplatePBar">
    					<ProgressBar Value="{Binding PBarValue}" IsIndeterminate="False" Width="100" Height="20"/>
    				</DataTemplate>
    			</ListView.Resources>
    			<ListView.View>
    				<GridView>
    					<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Text}"/>
    					<GridViewColumn Header="ProgressBar" CellTemplate="{DynamicResource DataTemplatePBar}"/>
    					<GridViewColumn Header="Button">
    						<GridViewColumn.CellTemplate>
    							<DataTemplate>
    								<Button Content="{Binding ButtonText}"/>
    							</DataTemplate>
    						</GridViewColumn.CellTemplate>
    					</GridViewColumn>
    				</GridView>
    			</ListView.View>	
    		</ListView>
    	</Grid>
    </Window>

    MainViewModel.cs
    public class MainViewModel
        {
            public List<ExampleItem> ExampleList { get; set; }
    
            public MainViewModel()
            {
                this.ExampleList = new List<ExampleItem>();
                Populate();
            }
    
            public void Populate()
            {
                
                for (int i = 1; i <= 5; i++)
                {
                    ExampleList.Add(new ExampleItem { Text = "Example" + i, PBarValue = 10*i,ButtonText = "Button " + i});
                }
            }
    
        }
    
        public class ExampleItem
        {
            public string Text { get; set; }
            public int PBarValue { get; set; }
            public string ButtonText { get; set; }
        }

    App.xaml
    public partial class App : Application
        {
            protected override void OnStartup(StartupEventArgs e)
            {
                base.OnStartup(e);
                MainViewModel main = new MainViewModel();
                MainWindow window = new MainWindow
                                        {
                                                DataContext = main
                                        };
                window.Show();
            }
        }

    Ответ написан
    Комментировать