Setting a style which in resource dictionary to a TextBox raises an exception RRS feed

  • Question

  • I have a TextBox named "textBox", and I want to change its style in code. I can use a key to find this style in resource dictionary. But when I set this style to the textBox, an exception was raised.

    Is that I missed something or did I do something wrong?

    				auto style = safe_cast<Windows::UI::Xaml::Style^>(App::Current->Resources->Lookup("TitleTextStyle"));
    				//auto style = safe_cast<Windows::UI::Xaml::Style^>(App::Application::Current->Resources->Lookup(L"TitleTextStyle"));
    				if(style != nullptr)
    				textBox->Style = style;
    // style is not null				

    The exception is here:

    Dino Wu

    • Edited by Dino Wu Tuesday, October 23, 2012 9:51 AM
    Tuesday, October 23, 2012 9:50 AM

All replies

  • Hi Dino,

    I assume you are using TitleTextStyle from StandardStyles.xaml. That style applies to a TextBlock, not to a TextBox. Your code will succeed if you use an appropriate style for the control.


    Tuesday, October 23, 2012 7:33 PM
  • Hi Rob,

    Thanks for your reply. You'are right, the TargetType of TitleTextStyle is applied to TextBlock. I'v got it missed.

    By the way, how should I check the real cause by exception? This issue raised an E_NETWORK_ERROR, so it confuses me that this condition is caused by a bad net work behavior.

    Thanks again!

    Dino Wu

    Wednesday, October 24, 2012 2:24 AM