Unable to add event handler
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Unable to add event handler

  1. #1
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    198

    Unable to add event handler

    Hi all,

    see attachment.
    in The Main window I can place a button, but I cannot add an event handler....
    I Use custom chrome to remove the window borders but keep the resize option.
    Also when I uncomment Initialisecomponents() I get a compile error

    where do I go wrong.

    Regards,

    Ger
    Attached Files Attached Files

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,485

    Re: Unable to add event handler

    The problem is the class name in the xaml file doesn't include the namespace that is in the code behind.
    You have:
    Code:
    x:Class="MainWindow"
    instead of
    Code:
    x:Class="Shader.MainWindow"
    You have several options to add a button handler, one is to press the space bar after clicking in a space inside the button declaration in the xaml file. When you press the spacebar, the intelli-sense will give you a list of items to choose from. Choose the Click item and then press the TAB key add a handler in the code behind.

    the xaml and code behind should end up as:
    Code:
    <Button x:Name="CloseWindow" Content="Close();" Click="CloseWindow_Click" HorizontalAlignment="Left" Height="50" Margin="133,109,0,0" VerticalAlignment="Top" Width="148"/>
    
    private void CloseWindow_Click(object sender, RoutedEventArgs e)
    {
    }
    Now keep in mind that this is the simple way to add a handler, but in WPF you probably really want to learn the MV-VM approach and use command bindings. You can get a great introduction to MV-VM pattern here: http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

    But honestly, learning WPF isn't something you can poke around in and pick up (or pick up correctly as you've found out). I'd suggest getting a book on WPF or at least spend time doing some online tutorials.

    One thing to understand is the editor in VS for WPF is like going back in time as compared to the WinForms editor. If you expect that experience, then you will be disappointed. On the other hand, once you understand WPF, you will find its binding features and customization abilities to be way ahead than WinForms (so it's lack of great editor support isn't going to matter much).

  3. #3
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    198

    Re: Unable to add event handler

    Hi Arjay,

    Long time on 'see' !!
    Thanks for the info will have a go.
    have some training video's on the subject.

    regards,

    ger

  4. #4
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    198

    Re: Unable to add event handler

    @Arjay,

    The namespace issue did the trick, everything is working as it should.
    But there is one little thing 'missing'.
    The Dropshadow is not avail anymore, I'm unable to draw outside the window/client region.
    So How can I make the drop shadow visible again? It can be done see the windows of VS2012 and outlook 2013.

    Regards,

    Ger

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,485

    Re: Unable to add event handler

    Quote Originally Posted by TBBW View Post
    The Dropshadow is not avail anymore, I'm unable to draw outside the window/client region.
    So How can I make the drop shadow visible again?
    If you started out with the drop shadow, what did you do to make it go away? Perhaps you removed it when you changed the code that caused the full namespace to change?

  6. #6
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    198

    Re: Unable to add event handler

    @Arjay,

    I do the custom window step by step.
    I wanted a resizeable window and dragable without the standard windows borders.
    It can be done with 9 routines. 1 for dragging and 8 for the resize that is 4 for the sides and 4 for the corners.
    But that is like inventing the wheel, so with the use of the shell lib. we can achieve this.

    So the next step is to implement the dropshadow or Glow, which one does not matter.
    Just like the standard windows have.
    If I add a dropshadow to the window in design view (blend) I can see it, as soon as I run the the app, it is gone.
    If I look at the 'rules' of xaml windows I see that I'm not allowed to draw outside the client area.
    But like the resize issue, there has to be a way, as office is using it. VS2012 and the game installer from Steam usses it.
    The big question is what is the 'magic call'.
    Most publications on XAML and/or WPF, if not all, do not cover this. As it is beyond scope


    Regards,

    ger

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center