我需要你的帮助。
此刻我正在制作一个通知小组。我需要更改ListBoxItem
的高度以响应许多消息的行。 Here's an example。
如您所见,第一个通知没有增加其高度,而TextBlock
的时间码刚刚消失。
这是我的代码示例:
<ListBox Width="350" Padding="0,0,0,10" Name="notificationArray">
<ListBoxItem Padding="10" MinHeight="80" Height="Auto" VerticalAlignment="Stretch">
<StackPanel>
<TextBlock FontSize="14" FontStyle="Italic" Foreground="Gray" Text="Channel name"/>
<TextBlock TextWrapping="WrapWholeWords" Text="This is very long notification. One, two, three, four, five, six, seven, eight, nine, ten."/>
<TextBlock Foreground="Gray" Text="HH:MM TT" FontSize="13"/>
</StackPanel>
</ListBoxItem>
</ListBox>
正如您在此处所看到的,我已经尝试了Height="Auto"
和VerticalAlignment="Stretch"
,但它仍然无效。有什么建议?无论如何,提前谢谢。
P.S。问题肯定在ListBoxItem
。我已经尝试过ListBox
和StackPanel
P.P.S这是一个较大的样本:
<Popup Grid.Column="6" Margin="0,50,0,0" Name="notificationPane" LostFocus="notificationPane_LostFocus" IsOpen="False" IsLightDismissEnabled="True">
<StackPanel Width="350" Background="WhiteSmoke" Padding="0,10,0,0">
<TextBlock Text="Notifications" HorizontalAlignment="Center" FontWeight="Bold"/>
<StackPanel Margin="0,10,0,0">
<TextBlock Text="You have no any notification" Name="noNotifText" Foreground="Gray" FontStyle="Italic" Padding="10" Visibility="Visible"/>
<StackPanel Name="notificationPanel" Visibility="Collapsed">
<ListBox Width="350" Padding="0,0,0,10" Name="notificationArray">
<ListBoxItem Padding="10" MinHeight="80">
<StackPanel>
<TextBlock FontSize="14" FontStyle="Italic" Foreground="Gray" Text="Channel name"/>
<TextBlock TextWrapping="WrapWholeWords" Text="This is very long notification. One, two, three, four, five, six, seven, eight, nine, ten."/>
<TextBlock Foreground="Gray" Text="HH:MM TT" FontSize="13"/>
</StackPanel>
</ListBoxItem>
<ListBoxItem Padding="10" VerticalAlignment="Stretch" Background="LightGray" MinHeight="80" Height="100">
<StackPanel>
<TextBlock FontSize="14" FontStyle="Italic" Foreground="Gray" Text="Channel name"/>
<TextBlock TextWrapping="WrapWholeWords" Text="This is very long notification. One, two, three, four, five, six, seven, eight, nine, ten."/>
<TextBlock Foreground="Gray" Text="HH:MM TT" FontSize="13"/>
</StackPanel>
</ListBoxItem>
</ListBox>
<Button Content="Clear all" HorizontalAlignment="Right" Margin="10,0,10,10"/>
</StackPanel>
</StackPanel>
</StackPanel>
</Popup>
答案 0 :(得分:0)
我从您上传到GitHub的开发分支下载整个项目并找到问题。由于您已定义了项目App.xaml
中ListBoxItem
的全局样式,因此将Height
的{{1}}属性设置为ListBoxItem
,限制50
1}}显示内容。
要解决您的问题,请注释此样式,或为第一个ListBoxItem
设置固定高度,为第二个设置ListBoxItem
,或为第一个项目设置更大的MinHeight
。
<Application.Resources>
<!--<Style TargetType="ListBoxItem">
<Setter Property="Height" Value="50"/>
</Style>-->
<Style TargetType="TextBlock" x:Key="ItemIcon">
<Setter Property="FontFamily" Value="Segoe MDL2 Assets"/>
<Setter Property="FontSize" Value="16"/>
<Setter Property="Margin" Value="5,5,20,2"/>
</Style>
...
</Application.Resources>