水平列表框项

时间:2015-06-25 14:41:13

标签: c# windows-phone-8.1

我想创建一个水平的ListBox项,就像键盘的建议一样 enter image description here

<ScrollViewer ZoomMode="Enabled"
          HorizontalScrollBarVisibility="Visible"
          VerticalScrollBarVisibility="Visible"
          HorizontalScrollMode="Enabled"
          VerticalScrollMode="Enabled">
            <StackPanel Orientation="Horizontal">
                <ListBox  Grid.Row="1"  Name="RecognizedListBox">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Foreground="Black"  Text="{Binding}" />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </StackPanel>
        </ScrollViewer>

当我点击按钮时,它必须显示水平列表 这是显示列表的代码

private async void RecognizeAllClick(object sender, RoutedEventArgs e)
    {

        resultword = recognizerShared.RecognizeStrokesList(InkCanvas.Children.ToList(), false);
        if (resultword.Equals(null) && resultword.Equals(""))
        {
            var messageBox = new MessageDialog("Text could not be recognized.");
            messageBox.Commands.Add(new UICommand("Close"));
            await messageBox.ShowAsync();
            resultword = null;
        }
        RecognizedListBox.ItemsSource = null;
        RecognizedListBox.ItemsSource = resultword;
    }

但它表明了这一点 enter image description here

我将Height =“30”添加到列表框后,它只显示一个建议,另一个显示无 enter image description here

解决

<ListBox x:Name="RecognizedListBox" >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical">
                        <TextBlock Width="30" Foreground="Black"  Text="{Binding}" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
        </ListBox>

enter image description here

2 个答案:

答案 0 :(得分:2)

尝试这样的事情:

<ListBox>
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal"/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    <ListBox.ItemTemplate>
        ...
    </ListBox.ItemTemplate>
</ListBox>

答案 1 :(得分:1)

尝试为控件指定特定大小,以便它不会扩展

<ListBox  Height=30 Name="RecognizedListBox"/>

或者让网格将行高设置为非*auto大小调整

<Grid.RowDefinitions>
        <RowDefinition Height="30" />