我想创建一个水平的ListBox项,就像键盘的建议一样
<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;
}
但它表明了这一点
我将Height =“30”添加到列表框后,它只显示一个建议,另一个显示无
解决
<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>
答案 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" />