This is very strange.
I have an XAML file that looks as follows...
<Window x:Name="window" x:Class="ix.Production.Title" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Title" Height="768" Width="1024" Loaded="window_Loaded"> <Window.Resources> etc...
And my code-beside that looks as follows...
using System; using System.Windows; using System.Windows.Media.Animation; using System.Threading; namespace ix.Production { public partial class Title : Window { public Title() { InitializeComponent(); } ....
This code refuses to compile because Visual Studio insists that the InitializeComponent "does not exist in the current context."
How can I fix this problem?
#91 – What InitializeComponent() Does The entry point into a WPF application, the Main function, is quite simple. It creates an instance of your Application object, calls its InitializeComponent method and then its Run method.
It was in 2006 that Windows Presentation Foundation (WPF) was released with . NET framework 3.0. Over the years it got improved and it is still now in the market in 2021.
Windows Presentation Foundation (WPF) in Visual Studio provides developers with a unified programming model for building line-of-business desktop applications on Windows.
One case I have seen this happening in when you copy paste an XAML control/window, etc. The InitializeComponent method exists in a corresponding .g.cs file that is automatically generated. In my case, after copy paste, Build Action for the XAML (in Properties window) was changed to "Resource". I changed it to "Page", and it started working fine.
I hope this helps.
The thread which helped me with this was The name 'InitializeComponent' does not exist....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With