Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从WPF c#中的列表框中获取文本框中的所有值?_C#_Wpf - Fatal编程技术网

如何从WPF c#中的列表框中获取文本框中的所有值?

如何从WPF c#中的列表框中获取文本框中的所有值?,c#,wpf,C#,Wpf,我试图从一个列表框中获取所有值,我从类中绑定了数据。目前这还不起作用,它返回类“sprint”的路径,但不返回数据 这是我的XAML <UserControl x:Class="Prototype.Sprint_Planning.PlanningIndex" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.m

我试图从一个列表框中获取所有值,我从类中绑定了数据。目前这还不起作用,它返回类“sprint”的路径,但不返回数据

这是我的XAML

<UserControl x:Class="Prototype.Sprint_Planning.PlanningIndex"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:Prototype.Sprint_Planning"
             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             mc:Ignorable="d"
             d:DesignHeight="570" d:DesignWidth="830">

    <!-- whole projects grid -->
    <Grid Grid.Column="1" Grid.Row="1">
        <Grid.RowDefinitions>
            <RowDefinition Height="60*" />
            <RowDefinition Height="239*" />

        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>

        </Grid.ColumnDefinitions>
        <Grid.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FFA0A0A0" Offset="1" />
                <GradientStop Color="#FFDADADA" />
            </LinearGradientBrush>
        </Grid.Background>

        <!-- create new project button -->
        <Grid Column="2">
            <Button Margin="10">
                <Grid Width="230">
                    <materialDesign:PackIcon Kind="Plus" />
                    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="Maak nieuwe Sprint aan"
                               FontFamily="Century Gothic" />
                </Grid>
            </Button>
        </Grid>


        <!-- project buttons -->
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="98*"/>
                <RowDefinition Height="17*"/>
            </Grid.RowDefinitions>
            <!-- LIST -->
            <ListView Margin="10,27,10,-444" Name="lvDataBinding" Grid.Row="1">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <WrapPanel>
                            <TextBlock x:Name="SelectionSprint" Text="Name: " />
                            <TextBlock Text="{Binding Name}" FontWeight="Bold" />
                            <TextBlock Text=", " />
                            <TextBlock MouseLeftButtonUp="SelectionSprint_MouseLeftButtonUp" x:Name="Id" Text="{Binding Id}" Tag="{Binding Id}" FontWeight="Bold" />
                            <TextBlock Text=" (" />
                            <TextBlock Text="{Binding Start_Date}" TextDecorations="Underline" Foreground="Blue" Cursor="Hand" />
                            <TextBlock Text=")" />
                        </WrapPanel>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </Grid>
    </Grid>
</UserControl>
类,其中存储了API数据

    public class SprintList
    {
        public List<Sprints> Sprints { get; set; }
    }
    public class Sprints
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Slug { get; set; }
        public int Setup { get; set; }
        public string Start_Date { get; set; }
        public string End_Date { get; set; }
        public int ProjectId { get; set; }
        public string Created_At { get; set; }
        public string Updated_At { get; set; }
    }

第一个问题是调用MessageBox时显示的路径是因为类中缺少一个ToString()。如果您想在MessageBox或控制台中打印或显示值,那么需要覆盖Sprints类的ToString()方法

例如:

public class Sprints
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Slug { get; set; }
    public int Setup { get; set; }
    public string Start_Date { get; set; }
    public string End_Date { get; set; }
    public int ProjectId { get; set; }
    public string Created_At { get; set; }
    public string Updated_At { get; set; }

    public override string ToString()
    {
       return $"{Name}";
    }
}
public class Sprints
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Slug { get; set; }
    public int Setup { get; set; }
    public string Start_Date { get; set; }
    public string End_Date { get; set; }
    public int ProjectId { get; set; }
    public string Created_At { get; set; }
    public string Updated_At { get; set; }

    public override string ToString()
    {
       return $"{Name}";
    }
}