问题描述
我正在开发一个WPF Master详细信息应用程序。我想每隔5秒自动刷新一次页面。我使用Dispatcher来实现这一目标。一切正常,但所选项目仅在5秒钟内突出显示,5秒后,默认选定行显示在顶部,替换我的选定项目。
I尝试设置issynchronizedwithcurrentitem =False,但是如果设置为false,则selecteditem(对于Master-detail场景)不起作用。
这是我试过的,
I am developing a WPF Master detail application. I would like to auto refresh my page every 5 secs. I have used a Dispatcher to achieve this. everything works fine, but the selected item is highlighted only for those 5 seconds, after 5 secs the default selected row is being displayed on the top replacing my selecteditem.
I have tried setting the issynchronizedwithcurrentitem="False", but with this set to false, the selecteditem ( for Master-detail scenario) doesn''t work.
this is what I have tried,
public partial class MainWindow : Window
{
WpfApplication1.PersonsEntities personsEntities;
System.Windows.Data.CollectionViewSource personViewSource;
System.Data.Objects.ObjectQuery<WpfApplication1.person> personQuery;
public MainWindow()
{
InitializeComponent();
}
private ObjectQuery<person> GetpersonQuery(PersonsEntities personsEntities)
{
var personQuery = personsEntities.person;
return personQuery as ObjectQuery<person>;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 5);
dispatcherTimer.Start();
}
protected void dispatcherTimer_Tick(object sender, EventArgs e)
{
personsEntities = new WpfApplication1.PersonsEntities();
personViewSource = ((System.Windows.Data.CollectionViewSource) (this.FindResource("personViewSource")));
personQuery = this.GetpersonQuery(personsEntities);
personViewSource.Source = personQuery.Execute(System.Data.Objects.MergeOption.AppendOnly);
}
}
推荐答案
这篇关于如何为主细节datagridview设置自动刷新绑定到实体框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!