2

こんにちは、ソリューションで mvvm を使用して WPF を使用していますが、問題があります。私はviewModelで使用しているこのオブジェクトを持っています:

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/>

問題は、Expander を展開すると、Listview 呼び出し ProblemListView の要素が次の Expander の下にあることです。

このエキスパンダー リストを正しく表示する方法を教えてください。エキスパンダーを展開すると、problemListView が正しく表示されます。

リストは動的であり、さまざまな数の要素を持つことができることを覚えておいてください

4

1 に答える 1

0

まず第一に、あなたの の設定Grid.Row="2"はあまり意味がないと思います。第二に、あなたのが問題を引き起こしています。なぜあなたがその下マージン(-127)を設定しているのかよくわかりません。ScrollViewerDataTemplatemarginExpander

に を指定する必要がありHeightますScrollViewer。そうしないと、 が大きくなるにつれてグリッド行が拡張され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}"
于 2012-12-04T17:41:12.110 に答える