locked
Usage of own defined DependencyProperty of type bool? failes RRS feed

  • Question

  • Hi,

    I have the following definition in a class library

            public static bool? GetGeneralUserFlag ( DependencyObject obj )
            {
                return (bool?)obj.GetValue(GeneralUserFlagProperty);
            }
    
            public static void SetGeneralUserFlag ( DependencyObject obj, bool? value )
            {
                obj.SetValue(GeneralUserFlagProperty, value);
            }
    
            public static readonly DependencyProperty GeneralUserFlagProperty =
                DependencyProperty.RegisterAttached("GeneralUserFlag", typeof(bool?), typeof(FrameworkExtension), new PropertyMetadata(null));
    

    I tried to use it in XAML as follows:

        <StackPanel xmlns:cle="using:ClassLibrary.Extensions" cle:FrameworkExtension.GeneralUserFlag="true" />
    

    Compile goes ok, on execution:

    An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in XXX.exe but was not handled in user code
    
    WinRT information: Failed to create a 'Windows.Foundation.IReference`1<Boolean>' from the text 'true'. [Line: 27 Position: 190]
    
    Additional information: Unspecified error

    Wednesday, May 23, 2012 7:27 AM

Answers

  • Hi NRN,

    Does this work for you if you use a non-nullable bool? If you do the same in your main app rather than in a class library?

    Setting nullable properties I custom controls is not a supported scenario. See this thread for a previous discussion of a similar issue.

    --Rob

    • Marked as answer by Min ZhuMember Wednesday, May 30, 2012 2:18 AM
    Thursday, May 24, 2012 2:57 AM
    Moderator