【发布时间】:2018-04-03 02:18:23
【问题描述】:
这是我当前有效的列表视图 XAML,我成功地用数据填充了我的列表视图。我尝试通过使堆栈布局中的项目可见/不可见以及通过调整堆栈布局和网格的高度请求来调整唯一单元格的行高。
<ContentPage.Resources>
<ResourceDictionary>
<DataTemplate
x:Key="ClassTemplate">
<ViewCell> <!-- I've tried to bind viewchells height (Height = "{Binding RowHeight}") but its not allowed to bind it -->
<StackLayout HeightRequest = "{Binding RowHeight}" HorizontalOptions = "FillAndExpand" VerticalOptions = "FillAndExpand">
<Button HeightRequest = "10" />
<Button IsVisible = "{Binding ExpandedRowVisibility}" HeightRequest = "300" />
<Grid VerticalOptions="Fill" HeightRequest = "{Binding RowHeight}">
<Grid.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding OpenRowDetails}"
CommandParameter="{Binding .}"
NumberOfTapsRequired="1" />
</Grid.GestureRecognizers>
</Grid>
</StackLayout>
</ViewCell>
</DataTemplate>
</ResourceDictionary>
</ContentPage.Resources>
<ListView
ItemsSource="{Binding List}"
HasUnevenRows="true"
Header="{Binding ShowHeaderObject}"
ItemTemplate="{StaticResource ClassTemplate}">
<ListView.HeaderTemplate>
<DataTemplate>
<StackLayout>
<Label
Text="{Binding .}"
HorizontalTextAlignment="Center"
TextColor="White" />
</StackLayout>
</DataTemplate>
</ListView.HeaderTemplate>
</ListView>
当我单击列表中的一行时,我会更新绑定到 Stacklayout、网格和按钮的 RowHeight 值(我已经单独和一起尝试了所有这三个),但我单击的行没有更新。
private string Height = "140";
public string RowHeight
{
get { return Height; }
set
{
private bool ExpandRow;
public bool ExpandedRowVisibility
{
get { return ExpandRow; }
set
{
this.ExpandRow = value;
OnPropertyChanged("ExpandedRowVisibility");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName]string propertyName = null)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public ICommand OpenRowDetails
{
get
{
return new Command(e =>
{
var Item = (ClassItemViewModel)e;
Item.RowHeight = "280";
Item.ExpandedRowVisibility = true;
});
}
}
如何更新我的代码,以便被点击的行将调整其行高但其他行保持不变?
【问题讨论】:
标签: xamarin xamarin.forms