Creating custom style buttons (and other controls) from C++ RRS feed

  • Question

  • Using the information at http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709909.aspx I was able to create very flexible custom buttons (Thanks Ron!) However, I am struggling to figure out how to create buttons programmatically in C++ based on the Style I created in XAML.  They work great from XAML but I cannot find any information on how to set the Style of a button created in C++ to the style I created in the app.xaml files.  I am not sure if I am going about it all wrong or if it is as simple as setting Style attribute of the button.  if it is the latter what do I set the button->Style to from my Style definition:


    I would create all of the buttons in XAML but within my app they are too dynamic to manage effectively in XAML.

    Thanks for any suggestions on how to do this! 


    Thursday, April 10, 2014 12:19 AM


  • I was able to find the answer. I have to ask where is all of this documented? 

    The trick is to create Style object and (with some fancy casting) assign it to the Style property of the control as so:

    auto st = App::Current->Resources->Lookup("BlockButton");

    m_bnLevelSelect[x][y]->Style = safe_cast <Windows::UI::Xaml::Style^>(st);


    • Marked as answer by RJS123 Thursday, April 10, 2014 2:40 AM
    Thursday, April 10, 2014 2:40 AM