listview c#uwp中的双线

listview c#uwp中的双线,c#,xaml,uwp,C#,Xaml,Uwp,我正试图解决这个问题,但没能找到解决办法。。 我有一本字典(键、值),如下所示: 在Xaml文件中,我在列表视图中显示字典,如下所示: <ListView x:Name="myDictionayList" Margin="0,25,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" Width="250" Height="640" FontSize="12" IsDoubleTapEnabled="Fal

我正试图解决这个问题,但没能找到解决办法。。 我有一本字典(键、值),如下所示:

在Xaml文件中,我在列表视图中显示字典,如下所示:

        <ListView x:Name="myDictionayList" Margin="0,25,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" Width="250" Height="640" FontSize="12" IsDoubleTapEnabled="False" IsHoldingEnabled="False" IsRightTapEnabled="False" IsTapEnabled="False" IsEnabled="False" IsHitTestVisible="False" Background="Transparent">
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="HorizontalContentAlignment" Value="Center"/>
                    <Setter Property="MinHeight" Value="25"/>
                </Style>
            </ListView.ItemContainerStyle>
        </ListView>
<ListView x:Name="MyListView">
    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel >
                <TextBlock Text="{Binding Key}"/>
                <TextBlock Text="{Binding Value}"/>
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

通过这种方式,我可以在ListView中显示字典的键值。现在,我想添加第二行,在这里我也输入字典的值,得到如下结果:

        <ListView x:Name="myDictionayList" Margin="0,25,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" Width="250" Height="640" FontSize="12" IsDoubleTapEnabled="False" IsHoldingEnabled="False" IsRightTapEnabled="False" IsTapEnabled="False" IsEnabled="False" IsHitTestVisible="False" Background="Transparent">
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="HorizontalContentAlignment" Value="Center"/>
                    <Setter Property="MinHeight" Value="25"/>
                </Style>
            </ListView.ItemContainerStyle>
        </ListView>
<ListView x:Name="MyListView">
    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel >
                <TextBlock Text="{Binding Key}"/>
                <TextBlock Text="{Binding Value}"/>
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>


谢谢你的建议

我想你指的是MyDictionaList.Items.Add(str.Key)在你的问题代码中

你在找这样的东西吗

<ListView x:Name="myDictionayList" Margin="0,25,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" Width="250" Height="640" FontSize="12" IsDoubleTapEnabled="False" IsHoldingEnabled="False" IsRightTapEnabled="False" IsTapEnabled="True" IsEnabled="True" IsHitTestVisible="False" Background="Transparent">
        <ListView.ItemContainerStyle>
            <Style TargetType="ListViewItem">
                <Setter Property="HorizontalContentAlignment" Value="Center"/>
                <Setter Property="MinHeight" Value="25"/>
            </Style>
        </ListView.ItemContainerStyle>
        <ListView.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <TextBlock Text="{Binding Key}" Grid.Row="0"></TextBlock>
                    <TextBlock Text="{Binding Value}" Grid.Row="1" Foreground="Gray"></TextBlock>
                </Grid>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

您可以通过编辑列表视图的
ItemTemplate
并添加
StackPanel
这样做:

        <ListView x:Name="myDictionayList" Margin="0,25,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" Width="250" Height="640" FontSize="12" IsDoubleTapEnabled="False" IsHoldingEnabled="False" IsRightTapEnabled="False" IsTapEnabled="False" IsEnabled="False" IsHitTestVisible="False" Background="Transparent">
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="HorizontalContentAlignment" Value="Center"/>
                    <Setter Property="MinHeight" Value="25"/>
                </Style>
            </ListView.ItemContainerStyle>
        </ListView>
<ListView x:Name="MyListView">
    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel >
                <TextBlock Text="{Binding Key}"/>
                <TextBlock Text="{Binding Value}"/>
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
产生如下结果:

        <ListView x:Name="myDictionayList" Margin="0,25,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" Width="250" Height="640" FontSize="12" IsDoubleTapEnabled="False" IsHoldingEnabled="False" IsRightTapEnabled="False" IsTapEnabled="False" IsEnabled="False" IsHitTestVisible="False" Background="Transparent">
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="HorizontalContentAlignment" Value="Center"/>
                    <Setter Property="MinHeight" Value="25"/>
                </Style>
            </ListView.ItemContainerStyle>
        </ListView>
<ListView x:Name="MyListView">
    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel >
                <TextBlock Text="{Binding Key}"/>
                <TextBlock Text="{Binding Value}"/>
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>


我想这就是你想要的。希望这能有所帮助。

mm不太确切……我想添加第二行作为第一行的描述(如我发布的图像)。相反,根据您的回答,键和值是两条不同的线。我编辑了我的回答,以使用XAML数据绑定和网格行。这就是你想要尝试做的吗?