2009-09-04 6 views
3

J'ai un fichier wpf ListView avec deux Expander. Lorsque les expandeurs se développent, la liste affiche de la place pour le contenu. Quand ils s'effondrent, la liste ne "reprend" pas cet espace supplémentaire. J'ai mis HorizontalAlignment et VerticalAlignment à Stretch partout. Y a-t-il un moyen de faire cela? Les colonnes Details et Chart contiennent les extensions. Voir le code ci-dessous. Merci.Impossible d'obtenir l'affichage de la liste WPF lors de l'effondrement des expandeurs dans la vue de liste

Ici, à

<Window.Resources> 

    <DataTemplate x:Key="StockPriceChangeCell"> 
     <StackPanel Orientation="Horizontal"> 
      <Label Name="stockPriceChangeValue" Foreground="{Binding StockPriceChangeColor}" Content="{Binding StockPriceChange}" Width="Auto"></Label> 
     </StackPanel> 
    </DataTemplate> 

    <DataTemplate x:Key="DetailsCell"> 
     <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
      <Expander Header="Details..." BorderBrush="DarkBlue" Width="200" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
       <Grid Name="stockDetailGrid" Background="Beige" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ShowGridLines="False"> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="96*" /> 
         <RowDefinition Height="6*" /> 
         <RowDefinition Height="96*" /> 
         <RowDefinition Height="6*" /> 
         <RowDefinition Height="96*" /> 
         <RowDefinition Height="6*" /> 
         <RowDefinition Height="96*" /> 
         <RowDefinition Height="6*" /> 
         <RowDefinition Height="96*" /> 
         <RowDefinition Height="96*" /> 
         <RowDefinition Height="96*" /> 
         <RowDefinition Height="6*" /> 
         <RowDefinition Height="96*" /> 
         <RowDefinition Height="6*" /> 
         <RowDefinition Height="96*" /> 
         <RowDefinition Height="6*" /> 
         <RowDefinition Height="96*" /> 
         <RowDefinition Height="6*" /> 
         <RowDefinition Height="96*" /> 
        </Grid.RowDefinitions> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="Auto" /> 
         <ColumnDefinition Width="Auto" /> 
        </Grid.ColumnDefinitions> 
        <Label Grid.Row="0" Grid.Column="0" Name="previousClosePrompt" FontWeight="Bold" FontSize="12" Height="28" Width="Auto">Prev Close:</Label> 
        <Label Grid.Row="0" Grid.Column="1" Name="previousCloseValue" FontWeight="Bold" FontSize="12" Height="28" Width="Auto" Content="{Binding StockDetails.PreviousClose}"></Label> 
        <Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator3" Margin="0,2" /> 
        <Label Grid.Row="2" Grid.Column="0" Name="openPricePrompt" FontWeight="Bold" FontSize="12" Height="28">Open:</Label> 
        <Label Grid.Row="2" Grid.Column="1" Name="openPriceValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.OpeningPrice}"></Label> 
        <Separator Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator5" Margin="0,2" /> 
        <Label Grid.Row="4" Grid.Column="0" Name="yearlyTargetEstimatePrompt" FontWeight="Bold" FontSize="12" Height="28">1y Target Est:</Label> 
        <Label Grid.Row="4" Grid.Column="1" Name="yearlyTargetEstimateValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.YearTargetEstimate}"></Label> 
        <Separator Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator6" Margin="0,2" /> 
        <Label Grid.Row="6" Grid.Column="0" Name="stockDaysRangePrompt" FontWeight="Bold" FontSize="12" Height="28">Day's Range:</Label> 
        <Label Grid.Row="6" Grid.Column="1" Name="stockDaysRangeValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.DaysRange}"></Label> 
        <Separator Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator7" Margin="0,2" /> 
        <Label Grid.Row="8" Grid.Column="0" Name="stockYearsRangePrompt" FontWeight="Bold" FontSize="12" Height="28">52wk Range:</Label> 
        <Label Grid.Row="8" Grid.Column="1" Name="stockYearsRangeValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.YearsRange}"></Label> 
        <Separator Grid.Row="9" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator8" Margin="0,2" /> 

        <Label Grid.Row="10" Grid.Column="0" Name="averageVolumePrompt" FontWeight="Bold" FontSize="12" Height="28">Avg Vol (3m):</Label> 
        <Label Grid.Row="10" Grid.Column="1" Name="averageVolumeValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.AverageVolume}"></Label> 
        <Separator Grid.Row="11" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator9" Margin="0,2" /> 
        <Label Grid.Row="12" Grid.Column="0" Name="marketCapPrompt" FontWeight="Bold" FontSize="12" Height="28">Market Cap:</Label> 
        <Label Grid.Row="12" Grid.Column="1" Name="marketCapValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.MarketCap}"></Label> 
        <Separator Grid.Row="13" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator10" Margin="0,2" /> 
        <Label Grid.Row="14" Grid.Column="0" Name="priceEarningRatioPrompt" FontWeight="Bold" FontSize="12" Height="28">P/E (ttm):</Label> 
        <Label Grid.Row="14" Grid.Column="1" Name="priceEarningRatioValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.PriceEarningsRatio}"></Label> 
        <Separator Grid.Row="15" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator11" Margin="0,2" /> 
        <Label Grid.Row="16" Grid.Column="0" Name="earningsPerSharePrompt" FontWeight="Bold" FontSize="12" Height="28">EPS (ttm):</Label> 
        <Label Grid.Row="16" Grid.Column="1" Name="earningsPerShareValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.EarningsPerShare}"></Label> 
        <Separator Grid.Row="17" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator12" Margin="0,2" /> 
        <Label Grid.Row="18" Grid.Column="0" Name="dividendYieldPrompt" FontWeight="Bold" FontSize="12" Height="28">Div &amp; Yield:</Label> 
        <Label Grid.Row="18" Grid.Column="1" Name="dividendYieldValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.DividendYield}"></Label> 
       </Grid> 
      </Expander> 
     </StackPanel> 
    </DataTemplate> 

    <DataTemplate x:Key="ChartCell"> 
     <StackPanel> 
      <Expander Header="Chart..." BorderBrush="DarkBlue" Width="200" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
       <Image Name="stockGraph" Stretch="None" Source="{Binding StockChart}"/> 
      </Expander> 
     </StackPanel> 
    </DataTemplate> 
</Window.Resources> 

Voici le listview:

   <TabItem Name="myStocksTab" Header="My Stocks" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
        <StackPanel Name="myStocksTabContainerPanel" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
         <Label Name="myStocksPrompt" Foreground="GhostWhite" Background="DarkBlue" FontSize="16" FontWeight="Bold">My Stocks</Label> 
          <ListView Name="stocksUIList" ItemsSource="{Binding}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch"> 
           <ListView.View> 
            <GridView> 
             <GridViewColumn Header="Action" CellTemplate="{StaticResource ButtonsCell}" Width="Auto"/> 
             <GridViewColumn Header="Company/Stock Symbol" Width="Auto" DisplayMemberBinding="{Binding CompanyName}"/> 
             <GridViewColumn Header="Last Trade" Width="Auto" DisplayMemberBinding="{Binding LastTrade}"/> 
             <GridViewColumn Header="Trade Time" Width="Auto" DisplayMemberBinding="{Binding StockDetails.TradeTime}"/> 
             <GridViewColumn Header="Change" CellTemplate="{StaticResource StockPriceChangeCell}"/> 
             <GridViewColumn Header="Volume" Width="Auto" DisplayMemberBinding="{Binding TradingVolume}"/> 
             <GridViewColumn Header="Details" CellTemplate="{StaticResource DetailsCell}" Width="215"/> 
             <GridViewColumn Header="Chart" CellTemplate="{StaticResource ChartCell}" Width="215"/> 
            </GridView> 
           </ListView.View> 
          </ListView> 
         <Button Name="addStock" FontSize="14" FontWeight="Bold" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Click="AddCompanyStock">Add Stock...</Button> 
        </StackPanel> 

Répondre

0

On dirait qu'il peut y avoir un bug de mise en page de toutes sortes dans le ListView. Avez-vous essayé d'appeler InvalidateVisual() sur le ListView dans l'événement Réduit de l'un des expanseurs? Cela peut faire l'affaire.

+0

Même problème, mais InvalidateVisual() ne semble pas avoir d'effet. – Squirrel

1

Je sais que c'est un post plus ancien, mais je cherchais une solution à ce problème et je voulais le mettre à jour avec ma solution.

Après quelques recherches j'ai pu le réparer en utilisant la solution trouvée ici: ListView with nested Expander not collapsing

En fait, je travaillais avec un ListView avec extenseurs dans le modèle d'objet. Lorsque la réduction de l'expanseur ne se redimensionnerait pas correctement. Aussi, lorsque le contenu de l'expandeur était plus grand que ListView, le défilement ne fonctionnerait pas correctement. Le correctif consistait simplement à remplacer ListView par ItemsControl et à placer ItemsControl dans un ScrollViewer.

Questions connexes