数据绑定到二维数组中的元素 [英] Data binding to an element in a two-dimensional array

查看:80
本文介绍了数据绑定到二维数组中的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列复选框,希望绑定到二维布尔数组.当我尝试设置具有两个索引的属性路径时,XAML不喜欢它.请参见下面的示例.

< CheckBox Grid.Column ="1"; Grid.Row ="2" Horizo​​ntalAlignment ="Center" VerticalAlignment ="Center" IsChecked =" { 绑定 RelativeSource = { RelativeSource FindAncestor AncestorType = { x : 类型 本地 : 每月 }}, 路径 = DaysOfWeek [ 0 0 ], 模式 = TwoWay}"/>

我在分隔DaysOfWeek索引的逗号上遇到错误. DaysOfWeek在我的代码后面是一个二维数组(我的班级名称是月刊).这是我得到的错误.

错误1 MarkupExtensions中的名称/值对必须具有``名称=值''格式,并且每个对都用逗号分隔. 'RelativeSource = {RelativeSource FindAncestor,AncestorType = {x:Type local:Monthly}},Path = DaysOfWeek [0,0],Mode = TwoWay}'不遵循此格式. Line 56 Position 124.


关于如何解决此问题的任何想法?我应该使用数组以外的东西吗? (我是最近开始使用C#的C ++程序员,所以也许有更好的解决方案,而且我陷入了C ++的思维定势.)

I have a series of checkboxes that I want to bind to a two-dimensional array of booleans.   XAML does not like it when I try to set a property path that has two indices.   See example below.

<CheckBox Grid.Column="1" Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:Monthly}}, Path=DaysOfWeek[0,0], Mode=TwoWay}"/>

I get an error on the comma that separates the DaysOfWeek indices.   DaysOfWeek is a two-dimensional array in my code behind (my class name is Monthly).  This is the error that I get.

Error 1 Name/value pairs in MarkupExtensions must have the format 'Name = Value' and each pair is separated by a comma. ' RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:Monthly}}, Path=DaysOfWeek[0,0], Mode=TwoWay}' does not follow this format. Line 56 Position 124. 


Any ideas on how I can fix this?   Should I be using something besides an array?   (I am a C++ programmer who has recently started using C# so maybe there is a better solution and I am stuck in a C++ mindset.)

推荐答案

我无法在wpf绑定中使用多维数组,这会导致错误.但是可以使用锯齿状的数组.

I can not use multi dimensional array in wpf binding that causes error. But jagged arrays can be used.


//variable...
public Color[][] Renkler { get; set; }

//assignment...
m.Renkler[6] = new Color[] { Colors.White, Colors.Black };


这篇关于数据绑定到二维数组中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆