WPF: Xaml, create an observable collection<object> in xaml in .NET 4.0

前端 未结 2 1491
感动是毒
感动是毒 2020-12-11 02:55

the web site says you can in .NET 4.0

I cant seem to do it though, what assesmbly references and xmlns\' do i need

the following does not work



        
2条回答
  •  甜味超标
    2020-12-11 03:30

    ObservableCollection is defined in the System assembly, so your namespace should read:

    xmlns:coll="clr-namespace:System.Collections.ObjectModel;assembly=System"
    

    You can find that information in MSDN at the top where it says:

    Namespace: System.Collections.ObjectModel
    Assembly: System (in System.dll)
    XMLNS for XAML: Not mapped to an xmlns.

    Note that the assembly has changed between v3.5 and v4.0. In v3.5 it was defined in the WindowsBase assembly. However, this was a drawback since you often would like to use the class without any WPF assemblies referenced. So maybe that is why they changed it.

    Furthermore, you should also check this blog post, which says that the new XAML features are not completely available in VS yet!

提交回复
热议问题