Performing control with an attached property in code (WPF)

I have UserControl1, and I want to instantiate it and set the attached property for it in the code located behind another UserControl2. In other words, in my UserControl2:

<UserControl2>
  <Canvas>
  </Canvas>
</UserControl2>

And I want to do:

<UserControl2>
  <Canvas>
     <UserControl1 Canvas.Left="100" ... />
  </Canvas>
</UserControl2>

How can I create UserControl1 with an attached property in the code behind UserControl2 ?

+3
source share
1 answer
UserControl1 ctrl = new UserControl1();
Canvas.SetLeft(ctrl, 100);
+3
source

Source: https://habr.com/ru/post/1753664/


All Articles