看一段代码你就知道了:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="460" Height="200" Title="Binding the Properties of Two Controls"> <Window.Resources> <Style targettype="TextBlock"> <Setter Property="FontSize" Value="16"/> <Setter Property="FontWeight" Value="Bold"/> <Setter Property="DockPanel.Dock" Value="Top"/> <Setter Property="HorizontalAlignment" Value="Center"/> </Style> <Style targettype="Canvas"> <Setter Property="Height" Value="50"/> <Setter Property="Width" Value="50"/> <Setter Property="Margin" Value="8"/> <Setter Property="DockPanel.Dock" Value="Top"/> </Style> <Style targettype="ComboBox"> <Setter Property="Width" Value="150"/> <Setter Property="Margin" Value="8"/> <Setter Property="DockPanel.Dock" Value="Top"/> </Style> </Window.Resources> <Border Margin="10" BorderBrush="Silver" BorderThickness="3" Padding="8"> <DockPanel> <TextBlock>Choose a Color:</TextBlock> <ComboBox Name="myComboBox" Selectedindex="0"> <ComboBoxItem>Green</ComboBoxItem> <ComboBoxItem>Blue</ComboBoxItem> <ComboBoxItem>Red</ComboBoxItem> </ComboBox> <Canvas> <Canvas.Background> <Binding ElementName="myComboBox" Path="SelectedItem.Content"/> </Canvas.Background> </Canvas> </DockPanel> </Border> </Window>
运行效果:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。