你可以用绑定去设置你的wrappanel宽度,比如:
<WrapPanel Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}, Path=ActuaoWidth}" >
上面的xaml会把宽度绑定到对应的ListBoxItem上,然后你可以绑定ListBoxItem的宽度到ListBox上:
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}" >
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Width" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}, Path=ActualWidth}"/>
</Style>
</ListBox.ItemContainerStyle>
当然,如果宽度需要计算, 你可以添加绑定的Converter属性。
Sheldon _Xiao
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.