dan blanchard

Hi, has anyone been able to specify the name property for a user control, so one can access it via code I am trying to do this"

<Window ...
xmlns:local="clr-namespace:NyNamespace"
>
...
<local:myUserControl Name="myUserControl1">

I am getting the typical warning for the invalid child element in namespace, but even worse, I cannot access the user control in code with the myUserControl1 variable, it says it does not exist in the current context. So it seems like that variable is not being created from the xaml.

How can I access the instantiated user control from code

Thanks,

dan



Re: Windows Presentation Foundation (WPF) Setting Name Property of user control... not working...

dan blanchard

OK, I figured it out, have to prefix with x: ... then it works... so, in the above example:

<local:myUserControl x:Name="myUserControl1" />




Re: Windows Presentation Foundation (WPF) Setting Name Property of user control... not working...

Ed Noepel

I think you have to specify attribute "x:Name" to set the name of a control within your assembly, or "Name" for a control outside your assembly.