Need some help...-VBForums
Results 1 to 10 of 10

Thread: Need some help...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    389

    Need some help...

    So lets say I open a new WPF application project in Blend 2, and draw a button (from the asset library) on the stage... Now I want to go into vb 2008 and code the button... I can't seem to get buttons, or any other control to expose its event routines in the code viewer in vb 2008...
    Visual Basic Rules!!!!!

  2. #2
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,381

    Re: Need some help...

    That is because it doesn't have any. If you look in the Xaml for the window and specificly for the button you will see that they do not have any name properties. If you place a name in the Xaml you will be able to access its properties (it looks after the code) so your button will look something like this:

    <Button>Stuff</Button>

    If you place Name="MyButton" in the opening tag like so:

    <Button Name="MyButton">Stuff</Button>

    It should work

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    389

    Re: Need some help...

    So I have to manually add a name parameter to all the controls before going in to VS?

    Also, when I design WPF windows in VS, why does it scale all the controls? How can I make it like old-school vb6.. Where resizing the form just shows blank form area, instead of stretching everything...
    Last edited by vbman213; Jan 28th, 2009 at 09:14 PM.
    Visual Basic Rules!!!!!

  4. #4
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    Re: Need some help...

    Not sure about Blend, but in Visual Studio, you will be given a default name property. You don't have to manually add it even if it's not there, just right click on it, properties, and enter the name.

    To make it 'not' dock with the rest of the form, you can either set the corresponding margin value to 0 or if you're in the designer, do you see those gray arrows pointing out from the control to the edge of the form? Click those. That should remove it and let you have that big barren area you want. It'll change your margin to look like:

    Margin="71,108,0,0"

    In this case, bottom and right margins have been removed.

  5. #5
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,381

    Re: Need some help...

    Right Mendhak, in blend certain properties, like name are not added unless needed, remember names are only needed if you want to access the control in code, although if you drag a control from the VS toolbox it will always have a default name. Regarding Scaling, WPF has a much more powerful layout model where it will try to make the layout fluid and stretch controls as the window grows. This may seem counter intuitive but as you become more familiar with layout and the different container controls (StackPanel,Grid,Canvas, etc) you can make your window (and the data it contains) lay itself out dynamically. For the moment though the easiest way to stop controls growing is to set the MaxHeight and MaxWidth equal to the same values as Height or Width, although I would play around with the anchor arrows and margins instead, as Mendhak suggested

  6. #6
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,381

    Re: Need some help...

    Has this been resolved?

  7. #7
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,598

    Re: Need some help...

    If the OP is just asking how he can assign a name to a control created in Blend, you dont have to go into the XAML and edit a name attribute into it. You can just click on the control in Blend and then in the Name field at the top of the Properties tab you can enter a name.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  8. #8
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Re: Need some help...

    In addition to this, it might be worth noting that an UIElement doesn't need a name to use event handlers.

    You can go:

    Code:
    <Button Click="Button_Click"></Button>
    if you want.
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  9. #9
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,598

    Re: Need some help...

    Very true and a good point to make people aware of. However its often easier to just give it a name so that you can access events and all properties/methods easily from the code behind
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  10. #10
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Re: Need some help...

    Indeed, in my opinion all elements that are being used in codebehind should be named in some descriptive way, along with their event handlers .

    Just thought I'd point it out since the context of the previous posts suggested that a name was a neccessity for assigning events and properties to an element. Might've just been me .
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.