kennykerr / modern

Modern C++ for the Windows Runtime
https://moderncpp.com/
MIT License
295 stars 36 forks source link

'Modern::ABI::Windows::Foundation::IReference<Modern::String>': no GUID has been associated with this object #7

Closed brucebob closed 9 years ago

brucebob commented 9 years ago

When trying to register a call back for a property change on a Text/Modern::String, I'm unable to get the value of the string. when I ran it to see the runtime class I got "Windows::Foundation::IReference'1"

        text.RegisterPropertyChangedCallback(text.TextProperty(), [](const DependencyObject& d, const DependencyProperty& p) 
        {
            const auto text_prop = d.GetValue(p);
            //text_prop.GetRuntimeClassName() = Windows::Foundation::IReference'1<String>
            const auto text_ref = text_prop.As<Windows::Foundation::IReference<String>>();
        });

The line with text_ref is giving me the compile error. 'Modern::ABI::Windows::Foundation::IReferenceModern::String': no GUID has been associated with this object

kennykerr commented 9 years ago

I'm not sure why you want to query for IReference. You can get the property value as follows:

text.RegisterPropertyChangedCallback(text.TextProperty(), [](DependencyObject const & d, DependencyProperty const & p)
{
    using namespace Windows::Foundation;

    IPropertyValue value = d.GetValue(p).As<IPropertyValue>();

    MODERN_TRACE(L"> %ls\n", value.GetString().Buffer());
});
brucebob commented 9 years ago

I figured I was using it wrong. Thank you for the correction. Your trace function is very handy I've been using it since I've seen all of your pluralsight courses. Keep it up!

kennykerr commented 9 years ago

Thanks!