如何在 Listview WPF 中显示我的列表成员

How to display my List member in Listview WPF

我有工作状态。

<ListView.View>
  <GridView>
    <GridView.Columns>
      <GridViewColumn
        Width="120"
        DisplayMemberBinding="{Binding Status}"
        Header="Durumu" />
      <GridViewColumn
        Width="180"
        DisplayMemberBinding="{Binding FromWho}"
        Header="Kimden" />
      <GridViewColumn
        Width="200"
        DisplayMemberBinding="{Binding Address}"
        Header="Adres" />
      <GridViewColumn
        Width="50"
        DisplayMemberBinding="{Binding Code}"
        Header="Kodu" />
      <GridViewColumn
        Width="0"
        DisplayMemberBinding="{Binding Order}"
        Header="Sipariş" />
    </GridView.Columns>
  </GridView>
</ListView.View>

但这对我来说还不够。

我有 wpf 应用程序。我正在学习绑定 我可以像上面的代码(列表视图)一样使用默认列表视图绑定。但我正在编辑自定义列表视图。并绑定数据

然而,当我尝试显示数据时,只出现了 myList 的系统名称。

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="*" />
    <RowDefinition Height="3*" />
    <RowDefinition Height="*" />
  </Grid.RowDefinitions>
  <DockPanel Grid.Row="1" VerticalAlignment="Center">
    <ListView
      x:Name="listVActiveOrder"
      Width="560"
      Height="222"
      Margin="10,10,0,0"
      HorizontalAlignment="Left"
      VerticalAlignment="Top"
      SelectionChanged="ListVActiveOrder_SelectionChanged"
      ItemsSource="{Binding TakingOrderList}">
      <ListView.GroupStyle>
        <GroupStyle>
          <GroupStyle.ContainerStyle>
            <Style TargetType="GroupItem">
              <Setter Property="Template">
                <Setter.Value>
                  <ControlTemplate>
                    <Grid>
                      <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                        <ColumnDefinition />
                      </Grid.ColumnDefinitions>
                      <TextBlock Grid.Column="0" Text="{Binding Address}" />
                      <TextBlock Grid.Column="1" Text="{Binding FromWho}" />
                    </Grid>
                  </ControlTemplate>
                </Setter.Value>
              </Setter>
            </Style>
          </GroupStyle.ContainerStyle>
        </GroupStyle>
      </ListView.GroupStyle>
    </ListView>
  </DockPanel>
  <ListBox
    x:Name="listProcessed"
    Grid.Row="2"
    Width="79"
    Height="29"
    Margin="721,16,0,0"
    HorizontalAlignment="Left"
    VerticalAlignment="Top"
    Visibility="Hidden" />
</Grid>
public LoginResponse loginResponse;
public RestClient client;
public listviewDeneme()
{
    client = new RestClient(Constants.APIURL);
    InitializeComponent();

}
  

private void ListVActiveOrder_SelectionChanged(object sender, SelectionChangedEventArgs e)
{

}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    listVActiveOrder.DataContext = new TakingOrderVM();
}

我错在哪里?

您可以将 ListViewDisplayMemberPath 属性 或 ListBox 设置为 TakingOrder 的 属性 的名称class您要显示的:

<ListBox
    x:Name="listProcessed"
    DisplayMemberPath="FromWho"
    ...

或者您可以定义一个 ItemTemplate:

<ListView
  x:Name="listVActiveOrder"
  Width="560"
  Height="222"
  Margin="10,10,0,0"
  HorizontalAlignment="Left"
  VerticalAlignment="Top"
  SelectionChanged="ListVActiveOrder_SelectionChanged"
  ItemsSource="{Binding TakingOrderList}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" Text="{Binding Address}" />
                <TextBlock Grid.Column="1" Text="{Binding FromWho}" />
            </Grid>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

如果您不打算使用 GridView,则没有理由使用 ListView 而不是 ListBox