<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具有地理數據庫匹配的地址,並且選擇得分最高的值。文本塊具有用於匹配的用戶輸入地址。如果地址相同,我希望前景爲綠色,否則爲紅色。我可以將整個UI元素傳遞給IValueConverter嗎?
我想也許我可以將整個TextBlock傳遞到dataconverter,獲得它的父StackPanel,獲得子0,投射到組合框中獲取第0個元素並進行比較,然後返回紅色或綠色。這是否可行?
否則,我想我必須遍歷視覺樹是一樣醜,我認爲