WPFのlistBoxを使用して、アクティビティフィードのようなUIをレンダリングしようとしています。listBoxは完全にレンダリングされており、ウィンドウのサイズが変更されると自動的にサイズが変更されます。しかし、内側のアイテムは本来あるべき内容を包んでいませんでした。そこで、内側のグリッドの幅をlistBoxのActualWidthに設定しました。これが私のXAMLと、私が達成しようとしていることを説明するためのスクリーンショットです。
<Grid x:Class="MyAddin.WPFControls"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:c="clr-namespace:MyAddin"
mc:Ignorable="d" Background="Transparent"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ShowGridLines="False" d:DesignHeight="221" d:DesignWidth="275">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock HorizontalAlignment="Stretch"
IsManipulationEnabled="True" Grid.Row="0"
Height="20" Grid.ColumnSpan="5" TextAlignment="Right" Padding="0,0,5,0" Margin="0,5,0,0" FontSize="14" FontStyle="Normal" FontWeight="ExtraLight">Activity Feed</TextBlock>
<ListBox Grid.Row="1" Name="listBox1" IsSynchronizedWithCurrentItem="True"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
VerticalContentAlignment="Stretch" ItemContainerStyle="{StaticResource ContainerStyle}"
AlternationCount="2" HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid MaxWidth="{Binding ElementName=listBox1, Path=ActualWidth}" Height="40">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="34"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0">
<Image Source="{Binding Path=AvatarURL}" Stretch="Fill" Width="32" Height="32" />
</Border>
<StackPanel Grid.Column="1">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=FirstName }" TextBlock.FontWeight="Bold"
HorizontalAlignment="Left" />
<TextBlock><Bold> - </Bold></TextBlock>
<TextBlock Text="{Binding Path=TS}" TextWrapping="Wrap"
TextTrimming="WordEllipsis" FontSize="9" Margin="0,2,0,0" FontWeight="ExtraLight" />
</StackPanel>
<TextBlock Text="{Binding Path=Comment}" TextWrapping="Wrap"
TextTrimming="CharacterEllipsis" HorizontalAlignment="Stretch"
VerticalAlignment="Top" Padding="0,0,5,0"/>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
ウィンドウのサイズを変更すると、リストボックスの内容が期待どおりに折り返されます。ただし、ウィンドウのサイズを元に戻すと、画像3に示すようにレイアウトが壊れています。ここで、2つの問題を解決するためのサポートが必要です。
- このサイズ変更の問題を修正するにはどうすればよいですか。
- コメントは折り返され、トリミングされていますが。最後に省略記号は表示されていません。
PS:私のアプリはOutlookアドインです。