我可以将整个UI元素传递给IValueConverter吗?
|
<DataTemplate>
<StackPanel Orientation=\"Vertical\" Name=\"AddressStackPanel\" >
<ComboBox Name=\"ComboBox\" ItemsSource=\"{Binding Path=MatchedAddressList}\" DisplayMemberPath=\"Address\" SelectedIndex=\"0\" SelectionChanged=\"ComboBox_SelectionChanged\"/>
<TextBlock Name=\"InputtedAddress\" Text=\"{Binding Path=InputtedAddress}\" Foreground={Hopefully pass the UI element to the dataconverter } />
</StackPanel>
</DataTemplate>
ComboBox的地址与来自地理数据库的具有最高评分的值匹配。 Textblock具有用于匹配的用户输入地址。如果地址相同,我希望前景为绿色,否则为红色。
我以为也许我可以将整个TextBlock传递到dataconverter中,获取其Parent StackPanel,将子级0,转换为Combobox,获取第0个元素并进行比较,然后返回红色或绿色。这可行吗?
否则我认为我必须遍历视觉树,就像我认为的那样丑陋
没有找到相关结果
已邀请:
2 个回复
泉秘胁
是。请参阅msdn文章
佬棠
的
绑定,该转换器将其相等值与
进行比较,并相应地返回returns5ѭ或
。 棘手的部分是上述转换器需要以某种方式跟踪
。这非常麻烦,因为我们无法使用
进行绑定,因此我们需要一个复杂的转换器。 另一方面,使用
可以更轻松地实现效果。例如:
然后,您将需要一个“ 9”来将两个传入的值转换为一个“ 12”。使用文档提供的示例确实很容易做到这一点。