A
A
AEG2013-11-23 05:03:43
C++ / C#
AEG, 2013-11-23 05:03:43

C# Prompt element for list

I want to create a list like in the screenshot
70aa2dd04674581de560105606d14fec.jpg
i.e. so that the records have both a progressbar and buttons.
What element in Visual Studio is more like this?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
P
Panicrust, 2013-11-23
@Panicrust

Oops, not there)

<Window x:Class="tblr.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid> 
        <ListBox>
        <StackPanel Orientation="Horizontal" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top">
            <Label Content="Имя_файла_123" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top" />
            <Label Content="Размер Х Мб" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top" />
            <ProgressBar IsEnabled="True" IsIndeterminate="True" Height="30" Width="146" HorizontalAlignment="Left" VerticalAlignment="Top"/>
            <Label Content="Загрузка" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top" />
            <Label Content="Время" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top" />
            <Button Content="Play file" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top"/>
        </StackPanel>
        <StackPanel Orientation="Horizontal" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top">
            <Label Content="Имя_файла_123" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top" />
            <Label Content="Размер Х Мб" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top" />
            <ProgressBar IsEnabled="True" IsIndeterminate="True" Height="30" Width="146" HorizontalAlignment="Left" VerticalAlignment="Top"/>
            <Label Content="Загрузка" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top" />
            <Label Content="Время" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top" />
            <Button Content="Play file" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top"/>
        </StackPanel>
        <StackPanel Orientation="Horizontal" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top">
            <Label Content="Имя_файла_123" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top" />
            <Label Content="Размер Х Мб" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top" />
            <ProgressBar IsEnabled="True" IsIndeterminate="True" Height="30" Width="146" HorizontalAlignment="Left" VerticalAlignment="Top"/>
            <Label Content="Загрузка" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top" />
            <Label Content="Время" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top" />
            <Button Content="Play file" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top"/>
        </StackPanel>
        </ListBox>
    </Grid>
</Window>

Y
Yuri, 2013-11-27
@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();
        }
    }

P
Panicrust, 2013-11-23
@Panicrust

I think it's more convenient to make each line of the list from several elements and output it as a list of lines. Or at once to do the table with elements. WinForms and WPF will have different implementations, so it's worth deciding from the very beginning. Every technology has its pitfalls

A
AEG, 2013-11-23
@AEG

Could you be more specific, I didn't understand either the first sentence or the second one?

N
Nikolai Turnaviotov, 2013-11-24
@foxmuldercp

Windows Forms - desktop applications - very limited functionality, considered "deprecated" because does not support window scaling on different resolutions, e.g.
Windows Presentation Framework - xml-based gui, extensible, convenient, with more advanced functionality.
You are actually invited to read about the differences between them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question