2

所以我有以下DataTemplate内容ListBox.ItemTemplate

<DataTemplate x:Key="Tweet">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="50"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Image 
                        Grid.Column="0"
                        Source="{Binding ProfileImageURL}"
                        Width="50" Height="50"/>
                    <Grid Grid.Column="1">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <TextBlock
                            Grid.Row="0"
                            FontSize="15"
                            FontWeight="Bold"
                            Text="{Binding User}"/>
                        <TextBlock
                            Grid.Row="1" TextWrapping="Wrap"
                            Text="{Binding Status}"/>
                        <DockPanel 
                            Grid.Row="2">
                            <TextBlock
                                DockPanel.Dock="Left"
                                FontSize="10" TextWrapping="WrapWithOverflow"
                                Text="{Binding TimeAgo}" TextAlignment="Justify"/>
                            <TextBlock
                                DockPanel.Dock="Left"
                                FontSize="10" TextWrapping="Wrap"
                                Text="{Binding Source}"/>
                        </DockPanel>
                    </Grid>
                </Grid>
            </DataTemplate>

问题是它不会自动调整到 ListBox 的大小。文本被剪裁: TwitBy 预览

如何解决?

这是 listBox XAML 定义:

<ListBox 
            x:Name="tweetsListBox" 
            Margin="3,0" 
            Grid.Row="1" 
            Background="{x:Null}" Grid.IsSharedSizeScope="True"
            ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            ItemTemplate="{DynamicResource Tweet}"/>

任何帮助,将不胜感激。

谢谢

4

1 回答 1

0

试试这个:

 <DataTemplate x:Key="Tweet">
      <Grid Width="{Binding ElementName=tweetsListBox, Path=ActualWidth>">
于 2010-04-18T09:09:54.893 回答