【问题标题】:Databinding Enum - The name 'StoreLocation' does not exist in the namespace数据绑定枚举 - 名称空间中不存在名称“StoreLocation”
【发布时间】:2015-06-10 21:18:42
【问题描述】:

我收到一个错误:

名称空间“clr-namespace:System.Security.Cryptography.X509Certificates;assembly=mscorlib”中不存在名称“StoreLocation”

上线:

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

我做错了什么?

<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>

【问题讨论】:

    标签: c# wpf enums wpfdatagrid


    【解决方案1】:

    尝试:

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

    【讨论】:

    • 该帖子被至少一位用户标记,大概是因为他们认为应该删除没有解释的答案。可能想为此添加一点。
    【解决方案2】:

    我知道这可能有点晚了,但是对于那些想知道快捷方式的人来说,在输入之后

    xmlns:crypto="
    

    开始输入

    using
    

    然后从类所在的位置粘贴命名空间(在VS中的类名上按F12并复制命名空间)并按

    ctrl + 空格键

    Visual Studio 将为您输入正确的 clr 类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-06
      • 1970-01-01
      • 2013-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-05
      • 2020-03-16
      相关资源
      最近更新 更多