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

时间:2022-10-05 14:12:28

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. But this doesn't seem to work. In the binding, I use a converter which converts a custom type to the required Double. But that should not be the source of the problem.

我有一个简单的网格,其中我将行高度绑定到数组成员。但是,如果来自用户的错误条目,则可以清除内容,即阵列索引变为无效。因此,我将FallbackValue设置为默认值。但这似乎不起作用。在绑定中,我使用转换器将自定义类型转换为所需的Double。但这不应成为问题的根源。

<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 ?

有任何想法吗 ?

1 个解决方案

#1


0  

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

Make your converter return DependencyProperty.UnsetValue

让您的转换器返回DependencyProperty.UnsetValue

#1


0  

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

Make your converter return DependencyProperty.UnsetValue

让您的转换器返回DependencyProperty.UnsetValue