Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I add to my main Window several User Controls Code Mainwindow.xaml.vb
 Dim u1 As UserControl = New CTRL_Engine(Brushes.Brown)
        u1.Height = 100
        u1.Width = 100
        u1.Name = "Test1"
            CTRL_Visu.Children.Add(u1)
        Canvas.SetLeft(u1, 520)
        Canvas.SetTop(u1, 20)

    Dim u2 As UserControl = New CTRL_Engine(Brushes.Red)
        u2.Height = 100
        u2.Width = 100
        u2.Name = "Test2"
            CTRL_Visu.Children.Add(u2)
        Canvas.SetLeft(u2, 10)
        Canvas.SetTop(u2, 20)

Usercontrol.xaml

Code Usercontrol.xaml.vb

  Public Shared Property Hintergrund As Brush = Brushes.Yellow

    Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
    Private Sub OnPropChanged(<CallerMemberName> Optional propName As String = "")
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName))
    End Sub

    Public Shared Property Colorr As Brush
        Get
            Return Hintergrund
        End Get
        Set(ByVal value As Brush)
            Hintergrund = value
            '       NotifyOfPropertyChange(Function() Colorr)
            '     RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(Colorr))
        End Set
    End Property

First, both Controls in the Windows have the same Color (as the last add) and i want later use the Controls to change individual the fill Color of the rectangle. how to handle it with the Binding, and how to handle later use of the added user controls?

What I have tried:

Read serveral postings, but not really found a solution
Posted
Updated 2-Jun-20 9:37am
v2

1 solution

Maybe the answer here will be helpful: How to bind code behind variables in WPF[^]
And also: User control binding in wpf[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900