gpt4 book ai didi

WPF 绑定(bind) FallbackValue 设置为绑定(bind)

转载 作者:行者123 更新时间:2023-12-01 13:47:37 25 4
gpt4 key购买 nike

有没有办法将另一个绑定(bind)作为后备值?

我正在尝试做这样的事情:

<Label Content="{Binding SelectedItem.Name, ElementName=groupTreeView,
FallbackValue={Binding RootGroup.Name}}" />

如果有人有另一个技巧来实现它,那就太好了。

最佳答案

您正在寻找的是称为 PriorityBinding 的东西(this 列表中的#6)

(来自文章)

The point to PriorityBinding is to name multiple data bindings in order of most desirable to least desirable. This way if the first binding fails, is empty and/or default, another binding can take it's place.



例如
<TextBox>
<TextBox.Text>
<PriorityBinding>
<Binding Path="LastNameNonExistant" IsAsync="True" />
<Binding Path="FirstName" IsAsync="True" />
</PriorityBinding>
</TextBox.Text>
</TextBox>

关于WPF 绑定(bind) FallbackValue 设置为绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1915562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com