带有基于项目内容的 itemswrapgrid 设置宽度的 UWP Listview [英] UWP Listview with itemswrapgrid setting width based on items content
本文介绍了带有基于项目内容的 itemswrapgrid 设置宽度的 UWP Listview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 UWP 的数据模板中有一个带有切换按钮的列表视图.我已将列表视图配置为 itemwrapgrid.我正在尝试根据切换按钮的内容长度为项目分配不同的宽度.谁能帮我做到这一点.
I have an Listview with togglebuttons in datatemplate in UWP. I have configured the listview as itemwrapgrid. I am trying to assign diffrent width for items based on toggle buttons content length. Can anyone help me to do this.
<ListView x:Name="lstVw1" IsMultiSelectCheckBoxEnabled="True" Margin="0,20,0,0">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Horizontal" Width="Auto" HorizontalAlignment="Stretch"></ItemsWrapGrid>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<ToggleButton Style="{StaticResource ButtonStyle}" Content="{Binding ItemText}" Click="ToggleButton_Click">
</ToggleButton>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ContentPresenter Padding="5"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
</ListView>
上面的 xaml 在列表中给出了相同大小的切换按钮
The above xaml gives equaly sized toggle buttons in the list
推荐答案
我已为上述内容创建了自定义换行面板.
I have created a custom wrap panel for the above.
这篇关于带有基于项目内容的 itemswrapgrid 设置宽度的 UWP Listview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文