WPF data binding -


consider 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 converted like:

 textblock.text = lbcolor.selecteditem.content; 

but how background bound same source? code:

 textblock.background = lbcolor.selecteditem.content; 

is incorrect. how can work? btw, works , shows correct background color.

the way see, system.windows.media.colors property given name, create solidcolorbrush , assign background property. there nothing in code points path.

this works because there built in conversion allows wpf convert string brush (which required type of background property).

if @ msdn documentation brush, can see decorated typeconverter attribute specifies converter of type brushconverter.

for general information type converters, have read of this article


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -