Vitalij
Vitalij

Reputation: 4625

Unable to access property of a nested UserControl

I have one UserControl nested inside the other UserControl, something like that:

<uc:MyControl1>
  <uc:MyControl2 Name="cheese"/>
</uc:MyControl2>

uc:MyControl2 contains a DP Name. And inside uc:MyControl1 I am exposing uc:MyControl2 using a standard property:

   public uc:MyControl1 ExposedMyProperty1 {get{return MyProperty1}}

But I still can't access it form the uc:MyControl1 :

<uc:MyControl1 ExposedMyProperty1.Name="Milk">
  <uc:MyControl2/>
</uc:MyControl2>

Intellisense shows only the properties of the UserControl, but not of my derived version of the UserControl. Meaning I see all the properties which comes from the UserControl, but don't see DP I have defined. So it looks like I am getting a UserControl instead of uc:MyControl1.

Am I missing something here?

Upvotes: 0

Views: 440

Answers (2)

Rune Grimstad
Rune Grimstad

Reputation: 36340

In your code sample you only expose a getter and not a setter. That may be your problem.

Try this:

public string ExposedMyProperty1 { get {return MyProperty1; } set {MyProperty1 = value;}}

But your code sample appears to be incomplete. For you say you are exposing a DependencyProperty, and your property is only a regular property. So this may not be the solution to your problem.

Upvotes: 1

Vitalij
Vitalij

Reputation: 4625

I have found an answer to my question. The answer is: you can't access nested properties from you xaml. I don't know what is the reason for WPF not allowing that..

The answer comes from this post

Upvotes: 0

Related Questions