我是 WPF 的新手。我有这个代码
<Window x:Class="ElementBinding.MultipleBindings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MultipleBindings" Height="320" Width="300">
<Grid>
<Slider Name="sliderFontSize" Margin="0,12,6,243"
Minimum="1" Maximum="40" Value="10"
TickFrequency="1" TickPlacement="TopLeft">
</Slider>
<TextBox Name="txtContent" Margin="0,44,0,208">Color should change here</TextBox>
<TextBlock Margin="3,150,3,3" Name="lblSampleText"
FontSize="{Binding ElementName=sliderFontSize, Path=Value}"
Text="{Binding ElementName=txtContent, Path=Text,Mode=TwoWay}"
Foreground="{Binding ElementName=lstColors, Path=SelectedItem.Tag}" >
Multiple Bindings
</TextBlock>
<ListBox Height="54" HorizontalAlignment="Left" Margin="12,90,0,0" Name="lstColors" VerticalAlignment="Top" Width="120" >
<ListBoxItem>Green</ListBoxItem>
<ListBoxItem>Red</ListBoxItem>
<ListBoxItem>Blue</ListBoxItem>
</ListBox>
</Grid>
</Window>
如果我在列表框中选择一个项目,文本块将不会出现。我认为问题出在“SelectedItem.Tag”中。我该如何解决这个问题?