简体   繁体   中英

mscorlib in .net core is missing in v3.1

I am working on wpf app. Using ObjectDataProvider am trying to bind enum to combobox . But mscorlib is not appearing when trying to reference in XAML. Does any package need to be installed for this?

There is no reason to reference mscorlib , just map the namespace to System.Runtime :

<ObjectDataProvider x:Key="name"
    xmlns:core="clr-namespace:System;assembly=System.Runtime" 
    MethodName="GetValues"
    ObjectType="{x:Type core:Enum}">
    <ObjectDataProvider.MethodParameters>
        <x:Type TypeName="local:YourType"></x:Type>
    </ObjectDataProvider.MethodParameters>
</ObjectDataProvider>

On digging more on how to bind enums in .net core, found an another way of achieving the same as described below.

The default namespace in XAML window is

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

I observered that, even without referring the 'system.runtime' assembly in XAML. we can still parse an enum and bind in XAML. Here is the code that is tried and successfully works.

Enum

public enum Members
{
    Member1,
    Member2
}

XAML

<ObjectDataProvider ObjectType="local:Members"
                            x:Key="key"
                            MethodName="GetValues">
     <ObjectDataProvider.MethodParameters>
           <x:Type TypeName="local:Members"/>
     </ObjectDataProvider.MethodParameters>
</ObjectDataProvider>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM