对XAML绑定FallBackValue使用复杂类型 [英] Use a complex type for XAML Binding FallBackValue

查看:80
本文介绍了对XAML绑定FallBackValue使用复杂类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种将UI元素绑定到复杂类型并具有另一个复杂类型的方法,例如 FallBackValue 。不幸的是,我没有找到关于该主题的任何内容。当我将 FallBackValue 设置为属性或类型的名称时,它总是显示为 string

I was searching for a way to bind a UI element to a complex type and have another complex type as FallBackValue. Unfortunately I didn't find anything on that topic. When I set FallBackValue to the name of a property or a type it is always displayed as a string :

<ContentControl Content="{Binding MyPathSelector, FallbackValue=model:PathSelector}"/>

在这种情况下,字符串


model:PathSelector

model:PathSelector

将会显示

推荐答案

如果您要避免使用标记语法,或者对多个绑定使用相同的后备对象,则可以使用以下资源:

Just in case you want to avoid tag syntax, or use the same fallback object for multiple bindings, you may use a resource:

<Window.Resources>
    <model:PathSelector x:Key="FallbackPathSelector" />
</Window.Resources>
...

<ContentControl Content="{Binding MyPathSelector,
                          FallbackValue={StaticResource FallbackPathSelector}}"/>

这篇关于对XAML绑定FallBackValue使用复杂类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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