【发布时间】:2014-08-03 05:00:22
【问题描述】:
我有一个桌面应用程序,允许从多台笔记本电脑更新表格中的信息。该程序是这样编写的,因此如果网络中断,人们可以继续工作。因此,它有一个专用的保存和刷新按钮,而不是 2 路绑定。但我无法让刷新工作。它使用列表框作为主框,使用网格获取详细信息。
XAML:
<Window.Resources>
<CollectionViewSource x:Key="nJSSEntriesViewSource" d:DesignSource="{d:DesignInstance my:NJSSEntry, CreateList=True}" CollectionViewType="{x:Type ListCollectionView}"/>
</Window.Resources>
<Grid DataContext="{StaticResource nJSSEntriesViewSource}" Height="858">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="720*" />
<RowDefinition Height="138"/>
</Grid.RowDefinitions>
<ListBox Height="626" HorizontalAlignment="Left" Name="listBox1" VerticalAlignment="Top" Width="200" DisplayMemberPath="FullName" ItemsSource="{Binding}" Margin="0,25,0,0" />
C#
private CombinedShowsContext _combinedShowsContext;
private CollectionViewSource _nJssEntriesViewSource;
private ListCollectionView _showsEntriesView;
private System.Data.Objects.ObjectQuery<NJSSEntry> GetNJSSEntriesQuery(CombinedShowsContext combinedShowsContext)
{
System.Data.Objects.ObjectQuery<NJSSEntry> nJssEntriesQuery = combinedShowsContext.NJSSEntries;
// Returns an ObjectQuery.
return nJssEntriesQuery;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_combinedShowsContext = new CombinedShowsContext();
_nJssEntriesViewSource = ((CollectionViewSource)(FindResource("nJSSEntriesViewSource")));
System.Data.Objects.ObjectQuery<NJSSEntry> nJssEntriesQuery = GetNJSSEntriesQuery(_combinedShowsContext);
_nJssEntriesViewSource.Source = nJssEntriesQuery.Execute(System.Data.Objects.MergeOption.AppendOnly);
_showsEntriesView = (ListCollectionView) _nJssEntriesViewSource.View;
}
private void RefreshButton1_Click(object sender, RoutedEventArgs e)
{
try
{
//_nJssEntriesViewSource.View.Refresh();
//_showsEntriesView.Refresh();
//listBox1.Items.Refresh();
CollectionViewSource.GetDefaultView(listBox1.ItemsSource).Refresh();
MessageBox.Show("Refreshed", "Refreshed",
MessageBoxButton.OK);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Refresh Failed",
MessageBoxButton.OK);
}
}
我已经在安装了该程序的两台 VMS 上对此进行了测试。我将更新并保存一个,然后点击另一个刷新,它应该会显示更改。目前没有任何反应。
我必须相信我刷新了错误的项目或对象。
我最终想用颜色更新列表框项目,以显示刷新后条目是否更新。
【问题讨论】:
标签: c# wpf entity-framework-4 master-detail