如何解决WPF ItemTemplate导致列表框内容大小问题
在WPF项目中,如果我在XAML中手动插入项目,则我的ListBox
可以正确呈现,例如:
<ListBoxItem>
<Grid Background="#7F271043" Width="200" Height="200">
<Grid.RowDefinitions>
<RowDefinition Height="110" />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Image Grid.Row="0" Source="Logo-40p.png" HorizontalAlignment="Center" Margin="10,10,10" />
<TextBlock Grid.Row="1" Text="Test Item" Foreground="White" Margin="10,0" FontSize="16" VerticalAlignment="Center" />
<local:Rating Grid.Row="2" HorizontalAlignment="Left" Height="24" Margin="10,0" VerticalAlignment="Center" Width="130" SelectedValue="4" IsReadOnly="True" />
<TextBlock Grid.Row="2" Text="Free" Foreground="#FF969292" Margin="0,0" FontSize="14" HorizontalAlignment="Right" VerticalAlignment="Center" />
</Grid>
</ListBoxItem>
ListBoxItem
的底部看起来像:
但是,当我换出<ListBoxItem>
的那一刻:
<ListBox.ItemTemplate>
<DataTemplate>
即使我保持其他所有条件不变,它也会导致我无法修复的等级控制出现大小调整问题(不响应手动尺寸或拉伸设置):
关于如何解决此问题的任何想法? ItemTemplate
/ DataTemplate
所做的事情是否可能导致控件不遵守手动设置的大小或由其所在的网格行设置的大小?
解决方法
设法解决此问题-XAML中手动定义的ListBoxItem
的行为与ItemTemplate
/ DataTemplate
的输出有所不同。
我的评分用户控件指定了设置的高度和宽度,这些高度和宽度被ListBoxItem
内的实现XAML(高度/宽度/拉伸)覆盖,但未被ItemTemplate
/ DataTemplate
内:
mc:Ignorable="d" Height="750" Width="4070" MouseLeave="UserControl_MouseLeave">
因此我改为将Height
/ Width
更改为DesignHeight
/ DesignWidth
来解决此问题:
mc:Ignorable="d" d:DesignHeight="750" d:DesignWidth="4070" MouseLeave="UserControl_MouseLeave">
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。