gpt4 book ai didi

c# - 无法设置多重绑定(bind)

转载 作者:行者123 更新时间:2023-11-30 14:23:33 24 4
gpt4 key购买 nike

我的多重绑定(bind)不工作。我收到错误消息:我的 xaml 中的命名空间“clr-NameSpace: myNamespace”中不存在名称“MatrixToDataViewConverter”(我已标记该行)。为什么?

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();
}
}
}
}

最佳答案

问题是,MatrixToDataViewConverter 是一个嵌套类。像这样重构 cs 文件:

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();
}
}
}

然后对您的解决方案执行清理重建。关闭 XAML 设计器并重新打开它。

关于c# - 无法设置多重绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45057054/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com