Binding a ComboBox selection to the background color of a border.

dmshow

Please forgive my ignorance. I am new to vb.net and WPF. I have a comboBox that has a list of colors like this. By the way this is in WPF.

Public Sub New()
    InitializeComponent()
    cmbColors.ItemsSource = GetType(Colors).GetProperties()
End Sub

In the XAML the comboBox is created as follows:

<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>

What I'm trying to do is when the program is run start with a beginning background color of grey, and when a new background color is selected from the comboBox the back ground will update. Here's the XAML of the element that I'm trying to bind to the selection.

<Border BorderBrush="{x:Null}" Grid.Column="1" Grid.Row="1" Background="{Binding Text, ElementName=cmbColors}">
    <TextBlock Text="PRACTICE" Style="{StaticResource linkButtons}"/>

I have gone through every (string) type in the property window for the border>background>create binding>Element>comboBox and for some reason (that I can't determine) I have either missed the appropriate one or am looking at this the wrong way.

Thank you in advance!!!

Mashton

You are binding the Background to a string, but the Background will need a ColorBrush. So, if your combo ItemsSource already contains items that are of ColorBrush then you can just bind to SelectedItem rather than Text.

Or you can use a converter in your Background binding, that takes the string and returns a SolidColorBrush, say.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Qt : Setting a border bottom on QtableView disables selection-background-color

From Dev

Binding Button IsEnabled to ComboBox Selection

From Dev

Border color based on background

From Dev

Transparent border with background color

From Dev

Change border color of Combobox in WPF

From Dev

Gradient background color on ::selection

From Dev

WPF Change Background color of a Combobox

From Dev

JavaFX - Border radius <-> Background color

From Dev

WPF Animate border background color

From Dev

ComboBox with Binding on SeclectedItem unable to change selection

From Dev

Inheriting default ComboBox to change border color or disable it

From Dev

Set border color of editable ComboBox on focus

From Dev

Set border color of editable ComboBox on focus

From Dev

How to reset background color of ::selection

From Dev

disable selection background color in css

From Dev

Background color of checkbox and selection in css

From Dev

css progress bar with background color and border color

From Dev

Change the border color of a label on user selection

From Dev

WPF Binding Border Color in Custom Button

From Dev

WPF Binding Border Color in Custom Button

From Dev

WPF Border Color Binding to parent Controls Tag

From Dev

How change the background color of the dropdown panel of Combobox

From Dev

Change the background color of a WPF editable ComboBox programmatically

From Dev

Changing background color of some rows in a combobox

From Dev

Why isnt my Background color working in a ComboBox

From Dev

Use ComboBox to change the background color of panel

From Dev

Change the background color of a WPF editable ComboBox programmatically

From Dev

Why isnt my Background color working in a ComboBox

From Java

React Native Border Radius with background color

Related Related

  1. 1

    Qt : Setting a border bottom on QtableView disables selection-background-color

  2. 2

    Binding Button IsEnabled to ComboBox Selection

  3. 3

    Border color based on background

  4. 4

    Transparent border with background color

  5. 5

    Change border color of Combobox in WPF

  6. 6

    Gradient background color on ::selection

  7. 7

    WPF Change Background color of a Combobox

  8. 8

    JavaFX - Border radius <-> Background color

  9. 9

    WPF Animate border background color

  10. 10

    ComboBox with Binding on SeclectedItem unable to change selection

  11. 11

    Inheriting default ComboBox to change border color or disable it

  12. 12

    Set border color of editable ComboBox on focus

  13. 13

    Set border color of editable ComboBox on focus

  14. 14

    How to reset background color of ::selection

  15. 15

    disable selection background color in css

  16. 16

    Background color of checkbox and selection in css

  17. 17

    css progress bar with background color and border color

  18. 18

    Change the border color of a label on user selection

  19. 19

    WPF Binding Border Color in Custom Button

  20. 20

    WPF Binding Border Color in Custom Button

  21. 21

    WPF Border Color Binding to parent Controls Tag

  22. 22

    How change the background color of the dropdown panel of Combobox

  23. 23

    Change the background color of a WPF editable ComboBox programmatically

  24. 24

    Changing background color of some rows in a combobox

  25. 25

    Why isnt my Background color working in a ComboBox

  26. 26

    Use ComboBox to change the background color of panel

  27. 27

    Change the background color of a WPF editable ComboBox programmatically

  28. 28

    Why isnt my Background color working in a ComboBox

  29. 29

    React Native Border Radius with background color

HotTag

Archive