简体   繁体   English

wpf绑定到数组索引时,fallbackvalue似乎不起作用

[英]wpf When binding to array index, fallbackvalue doesn't seem to work

I have a simple Grid in which i bind the Row height to an array member. 我有一个简单的网格,其中我将行高绑定到数组成员。 But the content may be cleared in case of wrong entries from the user, that the array index becomes invalid. 但是,如果用户输入错误,则可能会清除内容,从而使数组索引无效。 Therefore, I set the FallbackValue to a default value. 因此,我将FallbackValue设置为默认值。 But this doesn't seem to work. 但这似乎不起作用。 In the binding, I use a converter which converts a custom type to the required Double. 在绑定中,我使用转换器将自定义类型转换为所需的Double。 But that should not be the source of the problem. 但这不应该成为问题的根源。

<RowDefinition Name="Row1" Height="{Binding Path=item[0].value, Converter={conv:ItemValueToRowHeight}, FallbackValue=20}"/>

The debug output shows me that the wpf binding system still wants the array item, even if there are no items: 调试输出向我显示wpf绑定系统仍然需要数组项,即使没有项也是如此:

System.Windows.Data Warning: 17 : Cannot get 'Item[]' value ...

Any ideas ? 有任何想法吗 ?

Remarks 备注

A binding returns a value successfully if: 如果满足以下条件,则绑定成功返回值:

The path to the binding source resolves successfully.

The value converter, if any, is able to convert the resulting value.

The resulting value is valid for the binding target (target) property.

http://msdn.microsoft.com/en-us/library/system.windows.data.bindingbase.fallbackvalue.aspx http://msdn.microsoft.com/zh-cn/library/system.windows.data.bindingbase.fallbackvalue.aspx

Make your converter return DependencyProperty.UnsetValue 使您的转换器返回DependencyProperty.UnsetValue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM