Unable to set up multibinding
My multi-connectivity doesn't work. I am getting the error: The name "MatrixToDataViewConverter" does not exist in the namespace "clr-NameSpace: myNamespace" in my xaml (I have highlighted the line). What for?
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 file:
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();
}
}
}
}
source to share
The problem is what MatrixToDataViewConverter
is a nested class. Update the cs file as follows:
namespace myNamespace
{
/// <summary>
/// Interaction logic for ResultPopUp.xaml
/// </summary>
public partial class ResultPopUp : Window
{
public ResultPopUp(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();
}
}
}
Then follow Clean
and Rebuild
in your solution. Close the XAML designer and close it.
source to share
You cannot define IValueConverter
or IMultiValueConverter
as a nested class. Just put it in a separate file, or at least outside of your class ResultPopUp
.
For more information see: Bind Converter as Inner Class?
You may need to clean up and restore your solution after refactoring.
source to share