我有一个包含列表视图的扩展器。最初禁用扩展器,并在应用程序启动后的某个时间启用。
如果在InitializeComponent()之前我用至少一个项填充ListView的ItemsSource(一些可观察的集合,当然是在InitializeComponent之前创建),那么一切都很有用。扩展器正确扩展,项目显示应该。唯一的问题是,需要更多空间的新项目会被裁剪 - 我认为这意味着ListView没有正确刷新?
但是,如果我在InitializeComponent()之后的任何时候将项添加到集合中,则展开器只会扩展一点(仅几个像素)。当我强制ListView的宽度为某个大值时,扩展器会扩展,但插入列表的项目仅使用背景颜色呈现,没有内容......
我认为这与ListView初始化,刷新或者你有什么关系。代码如下:
XAML:
<DockPanel Name="mainPanel">
<Expander DockPanel.Dock="Right" ExpandDirection="Right" IsExpanded="False" IsEnabled="{Binding ExpanderEnabled}">
<Expander.Style>
<Style TargetType="Expander">
<Setter Property="Background" Value="#FFFF3333" />
<Style.Triggers>
<DataTrigger Binding="{Binding ExpanderEnabled}" Value="True">
<Setter Property="Background" Value="LightGreen" />
</DataTrigger>
</Style.Triggers>
</Style>
</Expander.Style>
<Expander.Header>
<Grid Width="30" VerticalAlignment="Top" HorizontalAlignment="Left">
<Grid Width="300" Height="300" VerticalAlignment="Top" HorizontalAlignment="Left">
<TextBlock Text="Expander Name" FontSize="12" FontWeight="Bold" Margin="22,170,0,0" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="0,1">
<TextBlock.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="-90"/>
<TranslateTransform/>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
</Grid>
</Grid>
</Expander.Header>
<ListView ItemsSource="{Binding Items}" BorderBrush="LightGreen" BorderThickness="3">
<ListView.Style>
<Style TargetType="ListView">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Black"/>
</Style.Resources>
</Style>
</ListView.Style>
<ListView.View>
<GridView>
<GridView.ColumnHeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Visibility" Value="Collapsed"/>
</Style>
</GridView.ColumnHeaderContainerStyle>
<GridViewColumn DisplayMemberBinding="{Binding Path=A, Converter={StaticResource aConverter}}" Width="Auto" />
<GridViewColumn DisplayMemberBinding="{Binding Path=B, Converter={StaticResource bConverter}}" Width="Auto" />
<GridViewColumn DisplayMemberBinding="{Binding Path=C, Converter={StaticResource cConverter}}" Width="Auto" />
<GridViewColumn DisplayMemberBinding="{Binding Path=D, StringFormat='\{0\} ds'}" Width="Auto" />
</GridView>
</ListView.View>
</ListView>
</Expander>
...