【发布时间】:2017-07-20 16:06:00
【问题描述】:
我的多重绑定不工作。我收到错误:名称 'MatrixToDataViewConverter' 不存在于我的 xaml 中的命名空间 'clr-NameSpace: myNamespace'(我已标记该行)。为什么?
xaml
<Window x:Class="myNamespace.PopMeUp"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:app="clr-namespace:myNamespace"
Title="PopMeUp" Height="300" Width="300">
<Window.Resources>
<app:MatrixToDataViewConverter x:Key="MatrixToDataViewConverter"/> <!-- Error here-->
</Window.Resources>
<Grid>
<DataGrid>
<DataGrid.ItemsSource>
<MultiBinding Converter="{StaticResource MatrixToDataViewConverter}">
<Binding Path="ColumnHeaders"/>
<Binding Path="RowHeaders"/>
<Binding Path="Values"/>
</MultiBinding>
</DataGrid.ItemsSource>
</DataGrid>
</Grid>
</Window>
.cs 文件:
namespace myNamespace
{
/// <summary>
/// Interaction logic for PopMeUp.xaml
/// </summary>
public partial class PopMeUp : Window
{
public PopMeUp(MWArray[] Result, int rows, int columns)
{
InitializeComponent();
}
public class MatrixToDataViewConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var myDataTable = new DataTable();
return myDataTable.DefaultView;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
}
【问题讨论】:
-
为什么你的
ResultPopUp类实现了IMultiValueConverter?您是否尝试过将您的MatrixToDataViewConverter放在单独的文件中,或者至少将ResultPopUp放在外部以便可以访问? -
为什么将
MatrixToDataViewConverter定义为嵌套类? -
抱歉,我忘记将 IMultiValueConverter 从 ResultPopUp 类中取出。我试图把它放在一个单独的类中,但它不起作用,我得到了同样的错误。 @MightyBadaboom
-
查看我的回答以获取更多信息。