Throws exception when i try to color the text box in WPF -


i trying set grey color text box.i trying following code throwing exception

"object reference not set instance of object."

because text box value null want text box in grey color irrespective of value present or absent.

here code used implement concept..

 <textbox     name="tbheadline"      text="{binding selectedstory.headline, updatesourcetrigger=propertychanged, validatesonexceptions=true, notifyonvalidationerror=true, validatesondataerrors=true}" validation.errortemplate="{staticresource errortemplate}"      grid.column="1"       grid.row="6"      textwrapping="nowrap"      d:layoutoverrides="height"      grid.columnspan="2"      horizontalalignment="stretch"      lostfocus="tbheadline_lostfocus"   /> 

here code used in xaml.cs

 tbheadline.foreground = brushes.gray; 

i tried following code also

tbheadline.background = brushes.gray; 

both throw same excepiton.

xaml elements created during code-behind's initializecomponent method if you're attempting access named element before call null.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -