Databinding Enum - The name 'StoreLocation' does not exist in the namespace

671 views Asked by At

I'm getting a error:

The name 'StoreLocation' does not exist in the namespace "clr-namespace:System.Security.Cryptography.X509Certificates;assembly=mscorlib"

on line:

<x:Type TypeName="crypto:StoreLocation" />

What I'm doing wrong?

<UserControl x:Class="Admin.Certificates"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:local="clr-namespace:Admin"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:crypto="clr-namespace:System.Security.Cryptography.X509Certificates;assembly=mscorlib">

<UserControl.DataContext>
    <local:CertificatesViewModel />
</UserControl.DataContext>

<UserControl.Resources>
    <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="GetEnumValues">
        <ObjectDataProvider.MethodParameters>
            <x:Type TypeName="crypto:StoreLocation" />
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
</UserControl.Resources>

<Grid>
    <DataGrid ItemsSource="{Binding Certificates}" AutoGenerateColumns="False">
       <DataGrid.Columns>
            <DataGridComboBoxColumn Header="StoreLocation"                   
                ItemsSource="{Binding Source={StaticResource GetEnumValues}}"
                SelectedValueBinding="{Binding StoreLocationValue}"/>
        </DataGrid.Columns>
    </DataGrid>
</Grid>
</UserControl>
2

There are 2 answers

1
Michal Ciechan On BEST ANSWER

try:

xmlns:crypto="clr-namespace:System.Security.Cryptography.X509Certificates;assembly=System"
0
mahlatse On

I know this might be a little late, but for those wondering a shortcut for this, after typing

xmlns:crypto="

start typing

using

then paste the namespace(pressing F12 on the class name in VS and copy the namespace) from where the class is located and press

ctrl + spacebar

Visual Studio will enter the correct clr type for you.