2012-11-01 95 views
2

嗨,大家好我是在解決方案上使用WPF和mvvm,我有一個問題。 我有這樣的對象,我使用一個ViewModel:在擴展器上調整大小的問題WPF

public class SuperCharacter : INotifyPropertyChanged 
{ 
    public List<Character> Characters { get; set; } 
    public string Name { get; set; } 
    private Character charactersExp; 
    private const string currentCharacterExpandedString = "CurrentCharacterExp"; 
    public Character CurrentCharacterExpanded 
    { 
     get { return this.charactersExp; } 
     set 
     { 
      this.charactersExp = value; 
      this.OnPropertyChanged(currentCharacterExpandedString); 
     } 
    } 

    public string CalcSize { get; set; } 

    public void OnPropertyChanged(string propertyName) 
    { 


     if (this.PropertyChanged != null) 
     { 
      this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
     } 

    } 

    public event PropertyChangedEventHandler PropertyChanged; 
} 

,我有這樣的觀點:

Window.Resources> 


    <DataTemplate x:Key="TrackPointUserSavedSearchDtoTemplate" DataType="{x:Type src:Character}"> 
     <StackPanel > 
      <TextBlock x:Name="caption" Margin="1" 
     Text="{Binding First}" MaxWidth="{Binding ElementName=image, Path=ActualWidth}" MaxHeight="40" /> 
     </StackPanel> 
    </DataTemplate> 

    <DataTemplate x:Key="DynamicUserSaveSearchesTemplate" DataType="{x:Type src:Character}"> 
     <ContentPresenter x:Name="content" ContentTemplate="{StaticResource TrackPointUserSavedSearchDtoTemplate }"/> 
    </DataTemplate> 

    <DataTemplate x:Key="IconoTrackPointUSTemplate" DataType="{x:Type src:SuperCharacter}"> 
     <ScrollViewer Grid.Row="2" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> 
      <Expander Height="180" Margin="12,0,0,-127" > 

       <Expander.Header> 
        <Binding Path="Name"></Binding> 
       </Expander.Header>     

        <ListView Name="ProblemListView" HorizontalContentAlignment="Stretch" ItemsSource="{Binding Characters}" SelectedItem="{Binding CurrentCharacterExpanded}" ItemTemplate="{StaticResource DynamicUserSaveSearchesTemplate}" Panel.ZIndex="20"> 
        </ListView>      
      </Expander> 
     </ScrollViewer> 
    </DataTemplate> 

    <DataTemplate x:Key="DynamicTrackPointUSTemplate" DataType="{x:Type src:SuperCharacter}" > 
     <ContentPresenter x:Name="content" ContentTemplate="{StaticResource IconoTrackPointUSTemplate }"/> 
    </DataTemplate> 
</Window.Resources> 
<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="42"></RowDefinition> 
     <RowDefinition Height="Auto"></RowDefinition>   
    </Grid.RowDefinitions> 
    <Label Content="Entitty's TrackPoint list:" Margin="12,5,76,9" Name="labelName" /> 
    <ListView Grid.Row="1" ItemsSource="{Binding SuperCharacters}" SelectedItem="{Binding CurrentSuperCharacterExpanded}" ItemTemplate="{StaticResource DynamicTrackPointUSTemplate}"> 
    </ListView> 
<Grid/> 

問題是,當我展開擴展從ListView控件調用ProblemListView元素低於到下一個擴展器。

我想知道我該如何讓這個擴展器列表看起來正確?如果我展開擴展器problemListView顯示正確。

只要記住,名單是動態的,可以有元素

+0

是否可以添加一些問題的圖片? – user1834059

+0

您是否需要在每個擴展器內部安裝一個ScrollViewer?或者僅僅是爲了'ListView' – dzavala

回答

0

首先,不同的數字,我覺得在你的DataTemplate設置Grid.Row="2"ScrollViewer並沒有太大的意義。其次,你的Expandermargin正在引起麻煩,我不明白你爲什麼要設置一個底部邊距(-127)。

您需要爲您的ScrollViewer指定Height,否則網格行將隨着ListView的增長而擴大。

嘗試將這些更改`IconoTrackPointUSTemplate:

<DataTemplate x:Key="IconoTrackPointUSTemplate" DataType="{x:Type WpfApplication1:SuperCharacter}"> 
    <ScrollViewer Height="50" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> 
     <Expander Margin="12,0,0,0" Header="{Binding Name}"> 
      <ListView Name="ProblemListView" 
         HorizontalContentAlignment="Stretch" 
         ItemsSource="{Binding Characters}" 
         SelectedItem="{Binding CurrentCharacterExpanded}" 
         ItemTemplate="{StaticResource DynamicUserSaveSearchesTemplate}" 
         Panel.ZIndex="20" /> 
     </Expander> 
    </ScrollViewer> 
</DataTemplate> 

正如一個建議,提示我如何改變擴展報頭的結合,可以節省相當一些空間做內聯:

Header="{Binding Name}"