1

我想将两级嵌套数组绑定到 Windows 8 Metro 风格应用程序中的 XAML 控件。数组看起来像(A、B、C 是顶级数组的元素)

一个
--W
- X
乙
--是
C
--Z

我想绑定W,XY的属性Z。实现这一目标的推荐方法是什么?我应该使用IValueConverter(这会导致很多代码)吗?

4

1 回答 1

0

If I understand your question correctly, I think you can use LINQ's SelectMany() in a property and report PropertyChanged. Something like this:

private string[][] _my2DArray;
public string[][] My2DArray
{
    get { return _my2DArray; }
    set 
    { 
        _my2DArray = value;
        OnPropertyChanged("My2DArray");
        OnPropertyChanged("InternalArrays");
    }
}

public IEnumerable<string> InternalArrays
{
    get { return _my2DArray.SelectMany(a => a); }
}

You may want to consider using an ObservableCollection instead of an array to notify changes within the collection.

于 2012-09-16T06:23:32.937 回答