Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 调整大小期间WPF ListBox中ListItem的大小调整问题_C#_Wpf_Xaml - Fatal编程技术网

C# 调整大小期间WPF ListBox中ListItem的大小调整问题

C# 调整大小期间WPF ListBox中ListItem的大小调整问题,c#,wpf,xaml,C#,Wpf,Xaml,我正在尝试使用WPF中的列表框呈现类似UI的活动提要。listBox可以完美地呈现,并在调整窗口大小时调整其自身大小。但是,内部项目并没有像应该的那样包装其内容。因此,我将内部网格的宽度设置为listBox的实际宽度。这是我的XAML和一些屏幕截图来解释我想要实现的目标 <Grid x:Class="MyAddin.WPFControls" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

我正在尝试使用WPF中的列表框呈现类似UI的活动提要。listBox可以完美地呈现,并在调整窗口大小时调整其自身大小。但是,内部项目并没有像应该的那样包装其内容。因此,我将内部网格的宽度设置为listBox的实际宽度。这是我的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>

活动提要
- 

它被渲染为图像1。如果我重新调整窗口的大小,列表框的内容将按照我的预期进行包装。但是,当我重新调整窗口的大小时,布局被破坏,如图3所示。我需要帮助解决以下两个问题:

  • 如何解决此调整大小问题
  • 尽管评论正在被修改 包裹和修剪。末尾没有显示椭圆 PS:我的应用程序是Outlook插件


    列表框上的属性ScrollViewer.HorizontalScrollBarVisibility应被禁用而不是隐藏。

    列表框上的属性ScrollViewer.HorizontalScrollBarVisibility应被禁用而不是隐藏