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?
if(App::Current->Resources->HasKey(L"TitleTextStyle"))
{
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