开发者

WPF: Vertical expander containing a ListView doesn't expand properly

I have an expander containing a list view. The expander is initially disabled, and enabled sometime after the application is started.

Everything works great if before InitializeComponent() I populate the ListView's ItemsSource (some observable collection, created of course before InitializeComponent) with at least one item. The expander expands correctly, items show as they should. The only problem then is that new items that require more space to be rendered appear cropped - I assume this means the ListView isn't refreshing properly?

However, if I add items to the collection anytime after InitializeComponent(), the expander only expands a little bit (just a few pixels). When I force the ListView's Width to be some large value, the expander does expand, but items inserted into the list are rendered just with the background color, with no content...

I assume this has something to do with the ListView initialization, refresh or what have you. Code follows:

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 W开发者_运维问答idth="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>
      ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜