C# 表格UWP-Can';t更新ViewCell中的视图(在iOS中工作)
我正在开发一个Xamarin.Forms MVVM移动应用程序,它的页面上有一个C# 表格UWP-Can';t更新ViewCell中的视图(在iOS中工作),c#,listview,xamarin,uwp,xamarin.uwp,C#,Listview,Xamarin,Uwp,Xamarin.uwp,我正在开发一个Xamarin.Forms MVVM移动应用程序,它的页面上有一个列表视图 我正在尝试访问列表视图中的一个查看单元格,然后在页面加载后立即更新该查看单元格中的内容。最终,我尝试设置动画(通过TranslateTo()),但出于测试目的,我只是尝试使ViewCell中的某些内容不可见(通过设置IsVisible=false) 它适用于我的iOS项目,但不适用于我的UWP项目。什么也没发生;ViewCell内容永远不会受到影响 基本准则是: ---------------- MyPag
列表视图
我正在尝试访问列表视图
中的一个查看单元格
,然后在页面加载后立即更新该查看单元格
中的内容。最终,我尝试设置动画(通过TranslateTo()
),但出于测试目的,我只是尝试使ViewCell
中的某些内容不可见(通过设置IsVisible=false
)
它适用于我的iOS项目,但不适用于我的UWP项目。什么也没发生;ViewCell
内容永远不会受到影响
基本准则是:
----------------
MyPage.cs
----------------
public MyPage() // constructor
{
_viewModel = new MyViewModel();
...
...
}
// on page load, subscribe to a message that modifies a ViewCell in the ListView;
// when that message is called in the ViewModel, it correctly modifies the ViewCell
// in iOS, but in UWP it does nothing;
protected override async void OnAppearing()
{
MessagingCenter.Subscribe<MyViewModel>(this, "ModifyViewCell", (sender) =>
{
// get item cell to modify (for testing, just get first one);
// see code in ListViewExt.cs a little farther down for GetCell() method
MyViewCellView viewCell = GetCell(0); // MyViewCellView : ViewCell
// modify cell - try different methods
viewCell.IsEnabled = false;
viewCell.View.IsVisible = false;
viewCell.MyViewInsideCell.IsVisible = false; // <<<==== breakpoint
}
}
-------------------
MyViewModel.cs
-------------------
public MyViewModel() // constructor
{
// send message to update ViewCell in ListView
Device.BeginInvokeOnMainThread(() => {
MessagingCenter.Send(this, "ModifyViewCell");
});
}
我还尝试在试图修改ViewCell
的代码行上设置一个断点(我在上面代码的注释中注意到了断点),当我将鼠标悬停在ViewCell
上时,Intellisense似乎表明我对ViewCell
视图有一个有效的引用(viewCell.MyViewInsideCell-它说它是一个Xamarin.Forms.Grid,就是这样)。但即使有一个有效的引用,我似乎也不能影响它的任何属性
这是一个Xamarin UWP错误吗?看起来是
我已经记录了一个日志
复制问题的位置。您能否显示有关单元格的更多详细信息
BindingContext
或共享一个简单的复制此问题的示例?我已添加了一个链接到可以复制问题的示例项目,还包括一个指向我记录的Bugzilla错误的链接。您能否显示有关单元格的更多详细信息BindingContext
或共享一个简单复制此问题的示例?我添加了一个链接到我的示例项目,可以在其中复制该问题,还包括一个指向我记录的Bugzilla错误的链接。
ListViewExt.cs
------------------------
// store ListView ViewCell's in dictionary for access later
public Dictionary<int, ViewCell> CellDict { get; set; } = new Dictionary<int, ViewCell>();
protected override void SetupContent(Cell cell, int index)
{
base.SetupContent(cell, index);
// add ViewCell to dictionary on SetupContent()
CellDict.Add(index, (ViewCell)cell);
}
public GetCell(int index)
{
return CellDict[index];
}