-
Jan 28th, 2009, 05:46 PM
#1
Thread Starter
Hyperactive Member
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!!!!!
-
Jan 28th, 2009, 06:17 PM
#2
Frenzied Member
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
-
Jan 28th, 2009, 09:04 PM
#3
Thread Starter
Hyperactive Member
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!!!!!
-
Jan 29th, 2009, 02:35 AM
#4
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.
-
Jan 29th, 2009, 05:14 AM
#5
Frenzied Member
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
-
Jan 30th, 2009, 05:44 AM
#6
Frenzied Member
-
Jan 30th, 2009, 01:55 PM
#7
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.
-
Feb 5th, 2009, 09:15 AM
#8
Frenzied Member
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.
-
Feb 5th, 2009, 09:42 AM
#9
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
-
Feb 5th, 2009, 09:49 AM
#10
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|