Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8207373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:58:25+00:00 2026-06-07T08:58:25+00:00

I have a new VB.Net WPF application. The MainWindow.xaml contains nothing more than a

  • 0

I have a new VB.Net WPF application. The MainWindow.xaml contains nothing more than a single ‘test’ button:

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Button Content="Test"
                Name="btnTest" />
    </Grid>
</Window>

The Application.xaml is untouched:

<Application x:Class="Application"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="MainWindow.xaml">
    <Application.Resources>

    </Application.Resources>
</Application>

The code behind is shown here. All I did was double click the button so the event handler is added automatically. I have also added the MainWindow to the View namespace.

Namespace View
    Class MainWindow
        ' A test button on the main window
        Private Sub btnTest_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnTest.Click
            MessageBox.Show("Hello world!")
        End Sub
    End Class
End Namespace

When I build this it doesn’t compile. Error message that I get is:

Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

When I remove the MainWindow from the View namespace everything is fine. So clearly the namespace is an issue. Can I add a Window to a namespace and do I need to change something else in the application to make it work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:58:28+00:00Added an answer on June 7, 2026 at 8:58 am

    You are breaking the partial class when you are putting it in a namespace. In addition to moving the VB.NET code behind to the namespace, you need to move the x:Class attribute as well:

    <Window x:Class="View.MainWindow" ... />
    

    And

    Namespace View
        Class MainWindow
           '...
        End Class
    End Namespace
    

    Visual Studio generates a partial VB.NET class that is a partial with your code behind. Since you moved the code behind to another namespace, it is no longer a partial with what Visual Studio generates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF application (.NET Framework 4) with a custom window-border. I've disabled
I have encountered something very strange, simple WPF application <Window x:Class=ListBoxSelection.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow
I have a new solution that is an ASP.NET MVC 2.0 application. I have
I have created a new ActionFilter for an ASP.NET MVC application that I'm creating.
I'm relatively new to .Net 4 and I am creating my FIRST WPF application
I have a WPF application targetting the .NET 4.0 Client Profile which needs to
I'm kinda new to WPF and .Net programming in general. I have downloaded this
I have a C# WPF .NET 4 application that has an icon in the
I have a WPF (C# and .NET 4) application that has a long running
I have a .Net client WPF application using System.DirectoryServices and LDAP for authentication. On

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.