Home All Groups Group Topic Archive Search About

Name Visability in XAML & Code Behind

Author
20 Apr 2007 11:08 PM
hufaunder@yahoo.com
In XAML you can give a name to each element so you can access it in
the code behind file. This works fine for a WPF application but not a
Windows Form application. Here is what I do:

1) Create a new WinForm application project
2) Add a new WPF User Control
3) In the XAML file give the grid a name, i.e. <grid Name="grid1">
4) In the code behind file trying to add this.grid1 but it's not
picked up.

Another strange thing is that when I try to compile the project it
does not see InitializeComponent. It says "The name
InitializeComponent does not exist in the current context". I guess
the two problem are related but how do I get it to work?

Again, if in 1) I create a WPF project everything works just fine.

Thanks
Author
22 Apr 2007 6:54 PM
Deniz Demircioglu
1. From command line, go to project folder
2. Notepad .csproj (or "vbproj")
3. In the csproj file, find this line:
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
4. Under this line, add the following line:
  <Import Project="$(MSBuildBinPath)\Microsoft.WinFx.targets" />
5. Now your project should compile without saying 'cannot find Initialize
Component'
6. After the first compile, you should be able to access the elements
defined in Xaml by using their name from code behind.

Thx

--
Developer,
Microsoft Office


Show quoteHide quote
"hufaun***@yahoo.com" wrote:

> In XAML you can give a name to each element so you can access it in
> the code behind file. This works fine for a WPF application but not a
> Windows Form application. Here is what I do:
>
> 1) Create a new WinForm application project
> 2) Add a new WPF User Control
> 3) In the XAML file give the grid a name, i.e. <grid Name="grid1">
> 4) In the code behind file trying to add this.grid1 but it's not
> picked up.
>
> Another strange thing is that when I try to compile the project it
> does not see InitializeComponent. It says "The name
> InitializeComponent does not exist in the current context". I guess
> the two problem are related but how do I get it to work?
>
> Again, if in 1) I create a WPF project everything works just fine.
>
> Thanks
>
>
Are all your drivers up to date? click for free checkup

Author
22 Apr 2007 11:29 PM
hufaunder@yahoo.com
On Apr 22, 11:54 am, Deniz Demircioglu
<DenizDemircio***@discussions.microsoft.com> wrote:
Show quoteHide quote
> 1. From command line, go to project folder
> 2. Notepad .csproj (or "vbproj")
> 3. In the csproj file, find this line:
>   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
> 4. Under this line, add the following line:
>   <Import Project="$(MSBuildBinPath)\Microsoft.WinFx.targets" />
> 5. Now your project should compile without saying 'cannot find Initialize
> Component'
> 6. After the first compile, you should be able to access the elements
> defined in Xaml by using their name from code behind.
>
> Thx
>
> --
> Developer,
> Microsoft Office
>
>
>
> "hufaun***@yahoo.com" wrote:
> > In XAML you can give a name to each element so you can access it in
> > the code behind file. This works fine for a WPF application but not a
> > Windows Form application. Here is what I do:
>
> > 1) Create a new WinForm application project
> > 2) Add a new WPF User Control
> > 3) In the XAML file give the grid a name, i.e. <grid Name="grid1">
> > 4) In the code behind file trying to add this.grid1 but it's not
> > picked up.
>
> > Another strange thing is that when I try to compile the project it
> > does not see InitializeComponent. It says "The name
> > InitializeComponent does not exist in the current context". I guess
> > the two problem are related but how do I get it to work?
>
> > Again, if in 1) I create a WPF project everything works just fine.
>
> > Thanks- Hide quoted text -
>
> - Show quoted text -

Wow, thanks. Don't know how I would have figured that out...

Bookmark and Share