Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3399752
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:48:34+00:00 2026-05-18T04:48:34+00:00

Consider the following XAML code: <StackPanel> <ListBox x:Name=lbColor> <ListBoxItem Content=Blue/> <ListBoxItem Content=Green/> <ListBoxItem Content=Yellow/>

  • 0

Consider the following XAML code:

    <StackPanel>
        <ListBox x:Name="lbColor">
            <ListBoxItem Content="Blue"/>
            <ListBoxItem Content="Green"/>
            <ListBoxItem Content="Yellow"/>
        </ListBox>
        <TextBlock>
            <TextBlock.Text>
                <Binding ElementName="lbColor" Path="SelectedItem.Content"/>
            </TextBlock.Text>
            <TextBlock.Background>
                <Binding ElementName="lbColor" Path="SelectedItem.Content"/>
            </TextBlock.Background>
        </TextBlock>
    </StackPanel>

I understand how Text property binding works. Internally it is converted to something like:

textBlock.Text = lbColor.SelectedItem.Content;

But how Background is bound to the same source? This code:

textBlock.Background = lbColor.SelectedItem.Content;

is incorrect. How can it work? BTW, it works and shows correct background color.

The only way I see, is to get System.Windows.Media.Colors property with given name, create SolidColorBrush from it and assign to Background property. But there is nothing in the code which points to this path.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:48:35+00:00Added an answer on May 18, 2026 at 4:48 am

    This works because there is a built in conversion that allows WPF to convert from a String to a Brush (which is the required type of the Background property).

    If you look at the MSDN documentation for Brush, you can see that it is decorated with a TypeConverter attribute that specifies a converter of type BrushConverter.

    For general information about type converters, have a read of this article

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XAML: <ListBox SelectedItem={Binding SelectedTeam}> <ListBoxItem Content={Binding Match.HomeTeam} /> <ListBoxItem Content={Binding
Consider the following, simple code: XAML: <Grid Height=60 Name=grid> <Grid.ColumnDefinitions> <ColumnDefinition Width=162* /> <ColumnDefinition
Consider following text: $content=<<<EOT { translatorID: f4a5876a-3e53-40e2-9032-d99a30d7a6fc, label: ACL, creator: Nathan Schneider, target: ^https?://(www[.])?aclweb\\.org/anthology-new/[^#]+,
Consider following: Partial View: <%= Html.ListBox(BlackList, Model.Select( x => new SelectListItem { Text =
Consider the following code: <Window x:Class=WpfApplicationWPF.CommandsWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=CommandsWindow Height=300 Width=300 PreviewMouseUp=Window_PreviewMouseUp MouseUp=Window_MouseUp >
Consider the following piece of Xaml <Grid Background=Blue> <Border Width=100 Height=60 BorderBrush=Black BorderThickness=2> <Border
Consider the following XAML: <ComboBox Name=CompanyComboBox HorizontalAlignment=Stretch ItemsSource={Binding Path=GlobalData.Companies} SelectedValuePath=Id SelectedValue={Binding Customer.CompanyId, ValidatesOnDataErrors=True} DisplayMemberPath=Name
Consider the following XAML (a UserControl): <Grid x:Name=LayoutRoot ScrollViewer.VerticalScrollBarVisibility=Disabled> <Grid HorizontalAlignment=Right Width=335.312 ScrollViewer.VerticalScrollBarVisibility=Disabled> <ed:BlockArrow
Consider following code: My problem is: 1) I can't seem to cast the errors
Consider following SWT code example: http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet151.java?view=co How can I separate the inline defined class?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.