WPF扩展器上的调整大小问题
大家好,我在解决方案中使用WPF和mvvm,我有一个问题。 我在viewModel上使用了以下对象:WPF扩展器上的调整大小问题,wpf,mvvm,resize,expander,Wpf,Mvvm,Resize,Expander,大家好,我在解决方案中使用WPF和mvvm,我有一个问题。 我在viewModel上使用了以下对象: public class SuperCharacter : INotifyPropertyChanged { public List<Character> Characters { get; set; } public string Name { get; set; } private Character charactersExp; private
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;
}
公共类超级字符:INotifyPropertyChanged
{
公共列表字符{get;set;}
公共字符串名称{get;set;}
个性特征;
私有常量字符串currentCharacterExpandedString=“CurrentCharacterExp”;
公共字符CurrentCharacterExpanded
{
获取{返回this.charactersExp;}
设置
{
this.charactersExp=值;
此.OnPropertyChanged(currentCharacterExpandedString);
}
}
公共字符串CalcSize{get;set;}
公共void OnPropertyChanged(字符串propertyName)
{
if(this.PropertyChanged!=null)
{
this.PropertyChanged(this,newpropertychangedventargs(propertyName));
}
}
公共事件属性更改事件处理程序属性更改;
}
我有这样的看法:
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/>
Window.Resources>
问题是,当我展开扩展器时,Listview调用ProblemListView中的元素位于下一个扩展器的下方
我想知道如何使这个扩展列表看起来正确?如果展开扩展器,problemListView将正确显示
请记住,列表是动态的,可以有不同数量的元素。首先,我认为在
数据模板中为滚动查看器设置Grid.Row=“2”
没有多大意义。第二,你的扩展器的边距造成了麻烦,我不太明白你为什么要设置底部边距(-127)
您需要为ScrollViewer
指定高度,否则网格行将随着列表视图的增长而扩展
尝试对“IConTrackPointUsTemplate”进行以下更改:
<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>
是否可以添加一些问题的图片?每个扩展器内是否需要ScrollViewer
?或者,这是否意味着仅适用于外部ListView
Header="{Binding Name}"