zyj*_*pox 7 wpf xaml listbox wrappanel styling
我被迫寻求帮助,而我自己却无法理解.我正在研究WPF-XAML桌面应用程序,其中GUI主要是动态生成的.
我的查询关于WrapPanel与ListBox项的样式.
请从我的usercontrol(.xaml)中找到一段代码:
<DockPanel x:Name="xResultPanel">
<ListView x:Name="bResultPanel" ItemsSource="{Binding ResultList, UpdateSourceTrigger=PropertyChanged}">
<ListView.ItemTemplate>
<DataTemplate>
<Expander Header="{Binding GroupName}" Style="{DynamicResource FeatureExpander2}">
<WrapPanel ItemWidth="140" Orientation="Horizontal">
<ListBox x:Name="ListOfTiles" ItemsSource="{Binding VideoSamples}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Width="120" Margin="10" HorizontalAlignment="Left">
<Image />
<TextBlock />
</StackPanel
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</WrapPanel>
</Expander>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DockPanel>
Run Code Online (Sandbox Code Playgroud)
上面的代码返回不是连续显示的ListBox项目,而是返回新行中的每个项目. 我试图为WrapPanel和ListBox设置MinWidth,Width等,但没有结果.
提前感谢所有相关技巧如何强制WrapPanel水平填充内容.
Dan*_*rth 12
问题是你WrapPanel只有一个孩子:ListBox.这意味着布局是通过ItemsPanel模板完成的ListBox.
试试这个:
<Expander Header="{Binding GroupName}" Style="{DynamicResource FeatureExpander2}">
<ListBox x:Name="ListOfTiles" ItemsSource="{Binding VideoSamples}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Width="120" Margin="10" HorizontalAlignment="Left">
<Image />
<TextBlock />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Expander>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7061 次 |
| 最近记录: |