C# 在Windows Phone运行时应用程序中更新绑定
我正在尝试修改Windows Phone运行时应用程序上C# 在Windows Phone运行时应用程序中更新绑定,c#,listview,windows-runtime,windows-phone-8.1,C#,Listview,Windows Runtime,Windows Phone 8.1,我正在尝试修改Windows Phone运行时应用程序上列表视图中的某些项目 项目通过简单的绑定绑定到ListView: this.defaultViewModel["myBinding"] = pi; 在xaml中: <ListView ItemsSource="{Binding myBinding}" ... > 然后,我将修改代码中的绑定: List<myItem> pi = (List<myItem>)this.defaultV
列表视图
中的某些项目
项目通过简单的绑定绑定到ListView:
this.defaultViewModel["myBinding"] = pi;
在xaml中:
<ListView ItemsSource="{Binding myBinding}" ... >
然后,我将修改代码中的绑定:
List<myItem> pi = (List<myItem>)this.defaultViewModel["myBinding"];
pi.RemoveAt(5);
List pi=(List)this.defaultViewModel[“myBinding”];
pi.RemoveAt(5);
现在,我想用新修改的pi
更新UI。我知道this.defaultViewModel[“myBinding”]=null
然后this.defaultViewModel[“myBinding”]=pi
可以工作,但它不会保持ListView的滚动位置(执行此操作后,它会跳到顶部)
我也尝试过,但似乎在Windows Phone运行时应用程序中没有UpdateTarget
那么,我应该怎么做才能强制刷新我的
列表视图的ItemsSource
,而不丢失它的滚动位置呢?您应该使用observeCollection
而不是List
。这样,就不需要取消设置和设置列表来更新ListView
要滚动到具有列表视图列表视图的列表视图中的项目,您可以调用列表视图。滚动到视图(项目)
,您应该使用可观察到的集合
,而不是列表
。这样,就不需要取消设置和设置列表来更新ListView
要滚动到具有列表视图列表视图的列表视图中的项目,您可以调用列表视图。滚动到视图(项目)
,您应该使用可观察到的集合
,而不是列表
。这样,就不需要取消设置和设置列表来更新ListView
要滚动到具有列表视图列表视图的列表视图中的项目,您可以调用列表视图。滚动到视图(项目)
,您应该使用可观察到的集合
,而不是列表
。这样,就不需要取消设置和设置列表来更新ListView
要滚动到具有列表视图列表视图的列表视图中的项目,可以调用列表视图。滚动到视图(项目)
需要实现INofityPropertyChanged
MSDN文章中的示例:
public class DemoCustomer : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
// This method is called by the Set accessor of each property.
// The CallerMemberName attribute that is applied to the optional propertyName
// parameter causes the property name of the caller to be substituted as an argument.
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private DemoCustomer()
{
}
private string customerNameValue = String.Empty;
public string CustomerName
{
get
{
return this.customerNameValue;
}
set
{
if (value != this.customerNameValue)
{
this.customerNameValue = value;
NotifyPropertyChanged();
}
}
}
}
需要实施INofityPropertyChanged
MSDN文章中的示例:
public class DemoCustomer : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
// This method is called by the Set accessor of each property.
// The CallerMemberName attribute that is applied to the optional propertyName
// parameter causes the property name of the caller to be substituted as an argument.
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private DemoCustomer()
{
}
private string customerNameValue = String.Empty;
public string CustomerName
{
get
{
return this.customerNameValue;
}
set
{
if (value != this.customerNameValue)
{
this.customerNameValue = value;
NotifyPropertyChanged();
}
}
}
}
需要实施INofityPropertyChanged
MSDN文章中的示例:
public class DemoCustomer : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
// This method is called by the Set accessor of each property.
// The CallerMemberName attribute that is applied to the optional propertyName
// parameter causes the property name of the caller to be substituted as an argument.
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private DemoCustomer()
{
}
private string customerNameValue = String.Empty;
public string CustomerName
{
get
{
return this.customerNameValue;
}
set
{
if (value != this.customerNameValue)
{
this.customerNameValue = value;
NotifyPropertyChanged();
}
}
}
}
需要实施INofityPropertyChanged
MSDN文章中的示例:
public class DemoCustomer : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
// This method is called by the Set accessor of each property.
// The CallerMemberName attribute that is applied to the optional propertyName
// parameter causes the property name of the caller to be substituted as an argument.
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private DemoCustomer()
{
}
private string customerNameValue = String.Empty;
public string CustomerName
{
get
{
return this.customerNameValue;
}
set
{
if (value != this.customerNameValue)
{
this.customerNameValue = value;
NotifyPropertyChanged();
}
}
}
}
很抱歉,我无法使ScrollIntoView
工作。无论是myListView.ScrollIntoView(pi[7])代码>或myListView.ScrollIntoView(myListView.Items[7])代码>工作。您能帮忙吗?在调用ScrollingToViewOh之前,请尝试添加listView.UpdateLayout()
。我很抱歉。我没有领会你关于可观察到的收集的观点。使用observateCollection
,我不需要再次将绑定设置为null
和pi
。所以我根本不需要滚动查看。它能自动完成一切。谢谢:)很抱歉,我无法让ScrollIntoView
工作。无论是myListView.ScrollIntoView(pi[7])代码>或myListView.ScrollIntoView(myListView.Items[7])代码>工作。您能帮忙吗?在调用ScrollingToViewOh之前,请尝试添加listView.UpdateLayout()
。我很抱歉。我没有领会你关于可观察到的收集的观点。使用observateCollection
,我不需要再次将绑定设置为null
和pi
。所以我根本不需要滚动查看。它能自动完成一切。谢谢:)很抱歉,我无法让ScrollIntoView
工作。无论是myListView.ScrollIntoView(pi[7])代码>或myListView.ScrollIntoView(myListView.Items[7])代码>工作。您能帮忙吗?在调用ScrollingToViewOh之前,请尝试添加listView.UpdateLayout()
。我很抱歉。我没有领会你关于可观察到的收集的观点。使用observateCollection
,我不需要再次将绑定设置为null
和pi
。所以我根本不需要滚动查看。它能自动完成一切。谢谢:)很抱歉,我无法让ScrollIntoView
工作。无论是myListView.ScrollIntoView(pi[7])代码>或myListView.ScrollIntoView(myListView.Items[7])代码>工作。您能帮忙吗?在调用ScrollingToViewOh之前,请尝试添加listView.UpdateLayout()
。我很抱歉。我没有领会你关于可观察到的收集的观点。使用observateCollection
,我不需要再次将绑定设置为null
和pi
。所以我根本不需要滚动查看。它能自动完成一切。谢谢:)