【发布时间】:2015-01-26 05:02:31
【问题描述】:
这里对WPF 和c# 非常陌生。我有兴趣拥有 ComboBox具有不同颜色选项,该选项将在选择选项时更新窗口的 Background。
我想通过DataBinding 执行此操作,但我是菜鸟,无法做到。这就是我所拥有的。
MainWindow.xaml
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
Background="{Binding SelectedValue,ElementName=combo,UpdateSourceTrigger=PropertyChanged}">
<StackPanel>
<ComboBox Name="combo">
<ComboBoxItem>lightcoral</ComboBoxItem>
<ComboBoxItem>khaki</ComboBoxItem>
</ComboBox>
</StackPanel>
</Window>
还有默认的MainWindow.xaml.cs(创建项目后就没碰过)
谢谢,如果您需要更多信息,请告诉我!
【问题讨论】:
-
你可以在link找到一些解释和例子
标签: c# wpf xaml data-binding combobox