Click to See Complete Forum and Search --> : Need some help...
vbman213
Jan 28th, 2009, 05:46 PM
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...
DeanMc
Jan 28th, 2009, 06:17 PM
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 :thumb:
vbman213
Jan 28th, 2009, 09:04 PM
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...
mendhak
Jan 29th, 2009, 02:35 AM
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.
DeanMc
Jan 29th, 2009, 05:14 AM
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 :thumb:
DeanMc
Jan 30th, 2009, 05:44 AM
Has this been resolved?
chris128
Jan 30th, 2009, 01:55 PM
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.
vbNeo
Feb 5th, 2009, 09:15 AM
In addition to this, it might be worth noting that an UIElement doesn't need a name to use event handlers.
You can go:
<Button Click="Button_Click"></Button>
if you want.
chris128
Feb 5th, 2009, 09:42 AM
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 :)
vbNeo
Feb 5th, 2009, 09:49 AM
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 :).
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.