Custom UserControl Property used by child element

后端 未结 4 852
花落未央
花落未央 2020-12-12 04:06

I\'m trying to get some WPF concepts down, so I\'ve put together a simple example of what I\'m trying to do. I would like to set a custom property of a user control, and hav

4条回答
  •  半阙折子戏
    2020-12-12 04:46

    Sorry to repost, but After re-reading you post, I think that you might be better off with templating. I've attached some samples in VB

    Window.xaml

    
        
            
        
    
    

    CircleInSquare.xaml.vb

    Partial Public Class CircleInSquare
        Public Property CircleColor() As Brush
            Get
                Return GetValue(CircleColorProperty)
            End Get
    
            Set(ByVal value As Brush)
                SetValue(CircleColorProperty, value)
            End Set
        End Property
    
        Public Shared ReadOnly CircleColorProperty As DependencyProperty = _
                               DependencyProperty.Register("CircleColor", _
                               GetType(Brush), GetType(CircleInSquare), _
                               New FrameworkPropertyMetadata(Brushes.Black))
    
    
        Public Property SquareColor() As Brush
            Get
                Return GetValue(SquareColorProperty)
            End Get
    
            Set(ByVal value As Brush)
                SetValue(SquareColorProperty, value)
            End Set
        End Property
    
        Public Shared ReadOnly SquareColorProperty As DependencyProperty = _
                               DependencyProperty.Register("SquareColor", _
                               GetType(Brush), GetType(CircleInSquare), _
                               New FrameworkPropertyMetadata(Brushes.Gray))
    
    End Class
    

    CircleInSquare.xaml

    
        
            
            
            
                
            
        
    
    

提交回复
热议问题