Sergey Metlov
Sergey Metlov

Reputation: 26341

Making control with attached property in code behind (WPF)

I have UserControl1 and I want to create it's instance and set attached property for it in the code behind of the other UserControl2. The other words, I have in the UserControl2:

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

And I want to do:

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

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

Upvotes: 3

Views: 1432

Answers (1)

Nir
Nir

Reputation: 29614

UserControl1 ctrl = new UserControl1();
Canvas.SetLeft(ctrl, 100);

Upvotes: 3

Related Questions