如何从 Windows.UI.Colors 得到 Window.UI.Color?
How to get Window.UI.Color from Windows.UI.Colors?
我有一个组合框 select 给定应用程序对象的背景颜色。我正在用下面的代码填充组合框,但我不知道如何检索 selected 值来更改其他对象的背景颜色。欢迎任何帮助。谢谢
XAML
<ComboBox x:Name="cbxBackgroundColor" SelectionChanged="cbxBackgroundColor_SelectionChanged" >
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Rectangle Fill="{Binding Name}" Width="32" Height="32" VerticalAlignment="Center" />
<TextBlock Text="{Binding Name}" Margin="10, 0, 0, 0" VerticalAlignment="Center" FontSize="12"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
代码隐藏
public VideoPage()
{
this.InitializeComponent();
cbxBackgroundColor.ItemsSource = typeof(Colors).GetProperties();
}
private void cbxBackgroundColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// Code to set MyObject.Background with cbxBackgroundColor.SelectedItem
}
以下代码在 wpf 中有效。
private void cbxBackgroundColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Color selectedColor = (Color)(cbxBackgroundColor.SelectedItem as PropertyInfo).GetValue(null, null);
this.Background = new SolidColorBrush(selectedColor);
or
MyObject.Background = new SolidColorBrush(selectedColor);
}
我有一个组合框 select 给定应用程序对象的背景颜色。我正在用下面的代码填充组合框,但我不知道如何检索 selected 值来更改其他对象的背景颜色。欢迎任何帮助。谢谢
XAML
<ComboBox x:Name="cbxBackgroundColor" SelectionChanged="cbxBackgroundColor_SelectionChanged" >
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Rectangle Fill="{Binding Name}" Width="32" Height="32" VerticalAlignment="Center" />
<TextBlock Text="{Binding Name}" Margin="10, 0, 0, 0" VerticalAlignment="Center" FontSize="12"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
代码隐藏
public VideoPage()
{
this.InitializeComponent();
cbxBackgroundColor.ItemsSource = typeof(Colors).GetProperties();
}
private void cbxBackgroundColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// Code to set MyObject.Background with cbxBackgroundColor.SelectedItem
}
以下代码在 wpf 中有效。
private void cbxBackgroundColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Color selectedColor = (Color)(cbxBackgroundColor.SelectedItem as PropertyInfo).GetValue(null, null);
this.Background = new SolidColorBrush(selectedColor);
or
MyObject.Background = new SolidColorBrush(selectedColor);
}