C# 如何在WPF c中的列视图中显示列表框项#
我在WPF中使用listbox控件,它的显示listbox项按行显示,但我想按列显示(类似于引导网格) 克马尔 试试这个C# 如何在WPF c中的列视图中显示列表框项#,c#,wpf,listbox,C#,Wpf,Listbox,我在WPF中使用listbox控件,它的显示listbox项按行显示,但我想按列显示(类似于引导网格) 克马尔 试试这个 <ListBox x:Name="lb_items"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <WrapPanel IsItemsHost="True" /> </Items
<ListBox x:Name="lb_items">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="10 0 0 0">
<Image Source="{Binding ImageSource}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
试试这个
<ListBox x:Name="lb_items">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="10 0 0 0">
<Image Source="{Binding ImageSource}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
列表框有一个名为ItemsPanel的属性,它决定了项目的呈现方式 在应用程序资源中的某个位置创建不同的ItemsPanelTemplate,以便您可以轻松地重用它:
<ItemsPanelTemplate x:Key="WrapPanelTemplate">
<WrapPanel />
</ItemsPanelTemplate>
<ItemsPanelTemplate x:Key="HorizontalStackPanelTemplate">
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
ListBox具有名为ItemsPanel的属性,该属性确定项目的呈现方式 在应用程序资源中的某个位置创建不同的ItemsPanelTemplate,以便您可以轻松地重用它:
<ItemsPanelTemplate x:Key="WrapPanelTemplate">
<WrapPanel />
</ItemsPanelTemplate>
<ItemsPanelTemplate x:Key="HorizontalStackPanelTemplate">
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
我认为使用ItemControl更容易,ListBoxThank兄弟会尝试这个我认为使用ItemControl更容易,ListBoxThank兄弟会尝试这个,Hanks@vercin会尝试这个。@basitraza你能把它标记为解决方案吗?如果它对你有帮助。事实上,这两个答案都有效,这就是为什么我不知道该标记哪一个:)@basitraza请你
标记对你帮助最大的响应。这将是一种感激帮助过你的人的表现;此外,它还将帮助这篇文章的其他读者。当响应被标记为答案时,读者会更加注意。我正要跳转到下一个搜索,但我没有看到任何对您的帖子的响应标记为答案-我认为问题可能没有解决,谢谢@vercin将尝试此项搜索。@basitraza您能将其标记为解决方案吗?如果它对你有帮助。事实上,这两个答案都有效,这就是为什么我不知道该标记哪一个:)@basitraza请你标记对你帮助最大的响应。这将是一种感激帮助过你的人的表现;此外,它还将帮助这篇文章的其他读者。当响应被标记为答案时,读者会更加注意。我正要跳转到下一个搜索,但我没有看到对标记为答案的您帖子的任何响应
-我认为问题可能没有解决,谢谢@Liero将尝试此搜索。VS中出现此错误消息提示名称FluidMoveBehavior
不存在于命名空间http://schemas.microsoft.com/expression/2010/interactivit
“它的工作伙伴,我没有在项目引用集中添加microsoft.expression.interactions.dll
。谢谢@Liero将尝试此项。此错误消息在VS中提示”名称FluidMoveBehavior
不存在于命名空间http://schemas.microsoft.com/expression/2010/interactivit
“它的工作伙伴,我不是在项目引用集中添加microsoft.expression.interactions.dll
。
<ListBox ItemsPanel="{StaticResource HorizontalStackPanelTemplate}">...
<ItemControl ItemsPanel="{StaticResource WrapPanelTemplate}">...
<ItemsPanelTemplate x:Key="FluidWrapPanel">
<WrapPanel>
<i:Interaction.Behaviors>
<ei:FluidMoveBehavior AppliesTo="Children" Duration="0:0:0.5">
<ei:FluidMoveBehavior.EaseY>
<SineEase EasingMode="EaseInOut" />
</ei:FluidMoveBehavior.EaseY>
<ei:FluidMoveBehavior.EaseX>
<CubicEase EasingMode="EaseInOut" />
</ei:FluidMoveBehavior.EaseX>
</ei:FluidMoveBehavior>
</i:Interaction.Behaviors>
</WrapPanel>
</ItemsPanelTemplate>
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"