English 中文(简体)
WPF: 在两个窗口之间分享可观察的收集资料?
原标题:WPF: Share an observable collection between two windows?

我很想知道,我如何能够在同一项目中分享两个不同的世界森林基金窗口之间的可观测信息。 局势似乎很容易,但我尚未找到解决办法。

我有Wow1, 有一个数据网,必须像这样进行可避免的收集:

        public Window1()
    {
        InitializeComponent();
        _bookLibrary = new ObservableCollection<BOOK>();       
        datagrid.ItemsSource = _bookLibrary;
    }

Within Window1, I am able to Add/Remove BOOK objects to/from the _bookLibrary collection and the datagrid updates correctly.

我还有一个窗口,即窗口2。 Window2使用也可生成BOOK物体的服务参考资料。 我想能够把Wow2 BOOK的物品添加到位于Wow1的图书收藏中(因为Wow1拥有整个图书馆的“主”数据网)。

我可能想的是,为Wow2 BOOK物体使用单独收集,然后将这种收集点/窗口1收集点合并起来。

任何想法/建议都将受到高度赞赏。 增 编

最佳回答

为了让我了解你的结构模式,并在这两种观点之间分享这一模式。 因此,你只是对你模式的相同财产(收集)持有束缚。

问题回答

There seems to be another not MVVM way of doing this by using CollectionViewSource:

<CollectionViewSource 
Source="{Binding Source={x:Static Application.Current}, Path=_BookLibrary}"   
x:Key="Window1View" />

<CollectionViewSource 
Source="{Binding Source={x:Static Application.Current}, Path=_BookLibrary}"
x:Key="Window2View" />

创建<代码>ItemsContainer?

<Window name="Window1">

<ListBox Name="Master" Grid.Row="2" Grid.ColumnSpan="3" Margin="8"
ItemsSource="{Binding Source={StaticResource Window1View}}">

......

</ListBox>
</Window>

Do the same for Window2.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签