2013-10-31 49 views
0

我已经创建了一个usercontrol并在第二个usercontrol中传递了它的程序集。我已经在Xaml文件中编写了正确的命名空间,但它仍然在说CLR clr-namespace is not defined in assembly如何解决此问题?谁能帮我。我的代码是:如何在WPF中包含程序集?

首先用户控件XAML文件:

<xmlns:local="clr-namespace:DesktopApplication.Roles"> <UserControl.Resources> <local:StringToColorConverter x:Key="StringToColorConverter"/> </UserControl.Resources>

二用户控件.CS文件:

using System; 
using System.Collections.Generic; 
using System.Collections.ObjectModel; 
using System.ComponentModel; 
using System.Linq; 

namespace DesktopApplication.Admin_Roles 
{ 


    public partial classCategoryTab : UserControl 
    { 

     public CategoryTab() 
     { 
      InitializeComponent(); 


     } 


    public class Data 
    { 
     public string Name { get; set; } 
     public string LastName { get; set; } 
     public string Color { get; set; } 
     public bool isactive { get; set; } 
    } 
    public class StringToColorConverter : IValueConverter 
    { 
     public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
     { 
      return (Color)ColorConverter.ConvertFromString((string)value); 
     } 

     public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
     { 
      return ((Color)value).ToString(); 
     } 
    } 
} 

回答

0

试试这个:

的UserControl1:

<UserControl x:Class="Sample.UserControl1" 
      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:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" xmlns:sample="clr-namespace:Sample" 
      d:DesignHeight="300" 
      d:DesignWidth="300"> 
     <UserControl.Resources> 
     <sample:StringToColorConverter x:Key="ddd"></sample:StringToColorConverter> 
     </UserControl.Resources> 
     <Grid>    
    </Grid> 
</UserControl> 

UserControl2:

using System; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Media; 

namespace Sample 
{ 
    /// <summary> 
    /// Interaction logic for UserControl2.xaml 
    /// </summary> 
    public partial class UserControl2 : UserControl 
    { 
     public UserControl2() 
     { 
      InitializeComponent(); 
     } 
    } 

    public class Data 
    { 
     public string Name { get; set; } 
     public string LastName { get; set; } 
     public string Color { get; set; } 
     public bool isactive { get; set; } 
    } 
    public class StringToColorConverter : IValueConverter 
    { 
     public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
     { 
      return (Color)ColorConverter.ConvertFromString((string)value); 
     } 

     public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
     { 
      return ((Color)value).ToString(); 
     } 
    } 
} 

我提出数据& StringToColorConverter “编译” 后,样品名称空间,然后一切工作正常。

而且也有在你的代码命名空间不匹配:

正确:

<xmlns:local="clr-namespace:DesktopApplication.Admin_Roles"> <UserControl.Resources> 

错误:

<xmlns:local="clr-namespace:DesktopApplication.Roles"> <UserControl.Resources> 
相关问题