Hi guys i'm using WPF with mvvm on a solution and i have an issue. I have this object that i am using on a viewModel:
大家好,我用WPF和mvvm来解决这个问题。我有一个在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;
}
And i have this view:
我的观点是:
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/>
The problem is when i expand the Expander the elements from the Listview call ProblemListView are below to next expander.
问题是,当我展开扩展器时,Listview调用问题列表视图中的元素会在下到下一个扩展器。
I like to know how can i make this expander list look correct? if i expand an expander the problemListView show correctly.
我想知道如何使这个扩展列表看起来正确?如果我展开一个扩展器,问题列表视图就会显示正确。
Just remember that the list is dynamic and can have different numbers of elements
只要记住列表是动态的,可以有不同数量的元素
1 个解决方案
#1
0
First of all, I think setting Grid.Row="2"
for the ScrollViewer
in your DataTemplate
doesn't make much sense. Second, the margin
of your Expander
is causing trouble, I don't quite get why you are setting a that bottom margin (-127).
首先,我想设置网格。对于DataTemplate中的ScrollViewer, Row=“2”没有多大意义。第二,扩展器的边距会引起麻烦,我不太明白为什么要设置底距(-127)。
You need to specify a Height
for your ScrollViewer
, otherwise the grid row will just expand as the ListView
grows.
您需要为您的ScrollViewer指定一个高度,否则,随着ListView的增长,网格行将会展开。
Try these changes to the `IconoTrackPointUSTemplate:
试试这些对“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>
Just as a tip, note how I changed the binding of the expander header, you can save quite some space doing the inline:
作为一个提示,请注意我如何更改了扩展头的绑定,您可以节省一些内联的空间:
Header="{Binding Name}"
#1
0
First of all, I think setting Grid.Row="2"
for the ScrollViewer
in your DataTemplate
doesn't make much sense. Second, the margin
of your Expander
is causing trouble, I don't quite get why you are setting a that bottom margin (-127).
首先,我想设置网格。对于DataTemplate中的ScrollViewer, Row=“2”没有多大意义。第二,扩展器的边距会引起麻烦,我不太明白为什么要设置底距(-127)。
You need to specify a Height
for your ScrollViewer
, otherwise the grid row will just expand as the ListView
grows.
您需要为您的ScrollViewer指定一个高度,否则,随着ListView的增长,网格行将会展开。
Try these changes to the `IconoTrackPointUSTemplate:
试试这些对“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>
Just as a tip, note how I changed the binding of the expander header, you can save quite some space doing the inline:
作为一个提示,请注意我如何更改了扩展头的绑定,您可以节省一些内联的空间:
Header="{Binding Name}"