【发布时间】:2014-05-30 15:23:32
【问题描述】:
请原谅我的无知。我是 vb.net 和 WPF 的新手。我有一个组合框,其中包含这样的颜色列表。顺便说一句,这是在 WPF 中。
Public Sub New()
InitializeComponent()
cmbColors.ItemsSource = GetType(Colors).GetProperties()
End Sub
在 XAML 中,组合框的创建方式如下:
<ComboBox Name="cmbColors" HorizontalAlignment="Left" Margin="29,35,0,0"
Grid.Row="1" VerticalAlignment="Top" Width="120">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Rectangle Fill="{Binding Name}" Width="16" Height="16"
Margin="0,2,5,2"/>
<TextBlock x:Name="cmbColorsText" Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
我要做的是当程序运行时以灰色的起始背景颜色开始,当从组合框中选择新的背景颜色时,背景将更新。 这是我尝试绑定到选择的元素的 XAML。
<Border BorderBrush="{x:Null}" Grid.Column="1" Grid.Row="1" Background="{Binding Text, ElementName=cmbColors}">
<TextBlock Text="PRACTICE" Style="{StaticResource linkButtons}"/>
我已经浏览了属性窗口中的每个(字符串)类型的边框>背景>创建绑定>元素>组合框,出于某种原因(我无法确定)我要么错过了合适的,要么正在寻找在这个错误的方式。
提前谢谢你!!!
【问题讨论】:
-
我忘了提到组合框按预期工作。我遇到的唯一问题是让边框背景根据选择改变颜色。
标签: wpf xaml binding combobox element