Expression > 論壇首頁 > Expression Blend + SketchFlow > Why is my custom property not shown?
發問發問
 

已答覆Why is my custom property not shown?

  • 2009年11月6日 下午 07:23assassin316 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    I'm building a custom Window and I'm now working on the Titlebar buttons, and have added this property:

     

    Public Shared AllowMinimizeProperty As DependencyProperty
    
    Public Property AllowMinimize() As Boolean
            Get
                Return CBool(GetValue(AllowMinimizeProperty))
            End Get
            Set(ByVal value As Boolean)
                SetValue(AllowMinimizeProperty, value)
    
                Dim img As Image = GetTemplateChild("imgMinimize")
    
                If img IsNot Nothing Then
                    img.Opacity = IIf(value, 1.0, 0.5)
                End If
            End Set
    End Property
    
    Public Sub New()
            AllowMinimizeProperty = DependencyProperty.Register("AllowMinimize", GetType(System.Boolean), GetType(BaseWindow), New UIPropertyMetadata(True))
    End Sub



    Now whenever I load up Blend, this property does not show up in the Miscellaneous section. If I change this property to NOT be a DependencyProperty, it will show, BUT it simple won't work. The image won't change it's opacity.

    What am I doing wrong?

解答

  • 2009年11月7日 下午 02:34Guenter Schwaiger 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    Hi assassin316,

    because when editing your Window in Blend the constructor of the root element (Window) is not called. Only the constructors of child elements are called. So your property is never registered.

    Try it out raise an execption in New() and edit the window in Blend.

    Hope it helps. 

    • 已標示為解答assassin316 2009年11月8日 下午 02:37
    •  
  • 2009年11月11日 下午 06:34Guenter Schwaiger 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    Try to register it  directly?

    Public Shared AllowMinimizeProperty As DependencyProperty = DependencyProperty.Register("AllowMinimize", GetType(System.Boolean), GetType(BaseWindow), New UIPropertyMetadata(True))

    Hope that helps.
    • 已標示為解答assassin316 2009年11月14日 下午 09:06
    •  

所有回覆

  • 2009年11月7日 下午 02:34Guenter Schwaiger 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    Hi assassin316,

    because when editing your Window in Blend the constructor of the root element (Window) is not called. Only the constructors of child elements are called. So your property is never registered.

    Try it out raise an execption in New() and edit the window in Blend.

    Hope it helps. 

    • 已標示為解答assassin316 2009年11月8日 下午 02:37
    •  
  • 2009年11月8日 下午 02:37assassin316 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    That is an interesting piece of info, thanks Guenter !   :)

    Coming back to this problem, how then can I go ahead and have my property show in Blend ???
  • 2009年11月11日 下午 05:49assassin316 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Sorry, I need to bump this message to find a solution  :\
  • 2009年11月11日 下午 06:34Guenter Schwaiger 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    Try to register it  directly?

    Public Shared AllowMinimizeProperty As DependencyProperty = DependencyProperty.Register("AllowMinimize", GetType(System.Boolean), GetType(BaseWindow), New UIPropertyMetadata(True))

    Hope that helps.
    • 已標示為解答assassin316 2009年11月14日 下午 09:06
    •  
  • 2009年11月11日 下午 08:23assassin316 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Perfect, i'll try that!

    Thanks again!

  • 2009年11月13日 下午 06:55D. Matsumoto 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    I'm learning about properties as well... just wondering if this solution worked for you?  If so, can you please mark it so us newbies know if it worked. :)  Thanks!
  • 2009年11月14日 下午 09:06assassin316 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Yes, it worked perfectly  :)  Just register the property on it's declaration, I've marked the answer above (answered by Guenter).