locked
How to set a background color of a Canvas in a C++ Metro App

    Question

  • Hi,

    i have a sample Metro app based on C++

    i have a canvas define in my Xaml (named "Sample.xaml")

    <Canvas Name="m_canvas"  HorizontalAlignment="Left" Height="748" Margin="0,0,0,0" VerticalAlignment="Top" Width="1034"  />

    in the C++ file ( Sample.xaml.cpp)

    i want to set the background color of this canvas at runtime -( not in the xaml file)

    i tried the following 

    SolidColorBrush ^col = ref new SolidColorBrush(Colors.Green);

    m_canvas->Background = col;

    but for some reason i get this error

    Error : identifier 'Colors' is undefined

    i must be missing something here - how do i resolve this ?

    NOTE: using namespace Windows::UI::Xaml::Media; is added in my CPP file

    Also, is there good metro app samples on using Canvas in C++ ? basically, some sample app where i could add shapes and other drawing objects at runtime . the msdn documentation is also very basic and dont have a good resource on C++ - everything shown is XAML and hardly any documentation on how to deal with the objects at programming level.

    i am finding it hard to write such (drawing based ) an app - 

    Any help is appreciated.

    Thanks,




    • Edited by naiveCoder Friday, August 10, 2012 2:35 PM
    Friday, August 10, 2012 2:22 PM

Answers

All replies