I was not able to find an answer to a simple question like this...
I'd like to resize a XAML control using keyboard, like I did in Windows Forms.
Example: in Windows Forms when I placed a TextBox in a form, I could resize it using [SHIFT]+[LeftArrow] or [SHIFT]+[RightArrow].
In this way I was able to resize that TextBox with a high degree of precision, without using the mouse.
If I do the same using XAML, the TextBox is being MOVED, not RESIZED.
I tried many keyboards combinations, but I was not able to find the equivalent of [SHIFT]+[LeftArrow] or [SHIFT]+[RightArrow] for XAML controls.
Do you know if such a shortcut exists?
Sorry if it seems a dumb question, but I'm missing this feature.
Not exactly an answer to my question, but I found very useful using Ctrl+MouseWheel: is a fast method to zoom the design part so that using the mouse becomes useful again when you REALLY need to be precise in resizing controls (like in a canvas container).
Make them big and resizing using mouse is easy and precise to the degree you wish (6400% is enough for everything, I think :-) )
Hit Ctrl+0 to go back to "Fit all" selection
Related
I'm making a custom dropdown button (since the one included in wpf requires too much hacking to style right). Now that i got the button bit out of the way i need to add the drop down part.
My first thought was to add a stackpanel and use that to contain the items but it gets cut off if it leaves the borders of the grid that the button is in. Next up was the popup primitive, it gets on top of everything nicely enough but position wise it just free floats and i haven't figured out how to make it follow the button it was spawned by. I also tried using contextmenu but that seems to have no positioning controls at all and just sits where the mouse made it..
Anyways wpf is a big package and I'm just getting into it, anybody know which direction i might find what I'm looking for?
Preferred approach normally is to use a Popup. You got two very important properties with a Popup
PlacementTarget and Placement
Setup a binding for PlacementTarget on the Popup to your custom Button and then use Placement to position the Popup accordingly w.r.t to the PlacementTarget(Button)
Placement accepts an enum of type PlacementMode which gives you quite a few options to position the Popup.
I need a control where user can pick only one option. Combobox is fine, radiobuttons are ok, but for some purpose I think about another crazy, but interesting solution.
There should be a slider control on a window and three possible positions of this sliding thing. I know this can be easily accomplished by setting slider's Minimum and Maximum plus TickFrequency and IsSnapToTickEnabled properties.
Now, is there a way how to add labels on left/right edge and center of slider showing user options within the slider? Or is it neccessary place labels/textblock below?
Last, though the most important thing is, how to associate integer slider positions with string options? I thought about switch, but this is wpf - there is "more wpf" solution, isn't it?
Just drag slider's rider to it's position and by binding set class string property to appropriate value.
Every control within WPF can have its visuals completely modified to suit your needs. This was/is the beauty of WPF over WinForms.
Can your slider have a TextBlock within it? Absolutely. Style as you desire and be on your way. A great article can be found via MSDN Magazine which outlines the approach to customizing WPF controls.
With regard to the integer values, use an IVauleConverter to translate the values to whatever you prefer.
i am trying to create a wpf app and have different parts in user controls.
in the navigation i have some buttons (now using the ribbon ctp). is it possible to change the main user control when different buttons are pressed in xaml. or is this just a bad way to do things?
sorry, really new to xaml and im trying to get my head arround it.
Further to what Carlo has said,
The way we do it is to have a blank grid in the place you want your controls to all appear and then use BlankGrid.Children.Clear() and BlankGrid.Children.Add() to set up which control is visible in this position.
We found that was the nicest programatically as we have a large number of custom controls, but Carlo's method would work nicely if you wanted to use the designer.
I think this is a pretty regular procedure in WPF. In my experience, me and other programmers put the controls where we want to show them and make their visibility hidden, collapsed or visible depending on what we want to show the user.
When I drag a control from the toolbox on to the Visual Studio 2008 WPF design surface, it sets a margin based on where I dropped it and a default size.
Is there any way to prevent VS setting those? When I drop a control on a stackpanel I want it to flow in to the existing controls in the panel.
Thanks!
I've never found a way to prevent this. I just type the XAML instead.
EDIT:
I wrote the above nearly three years ago. In the meantime, it would appear that the design-time experience has gotten a lot better.
While the designer still adds hard-coded margins if you drag-and-drop, there are ways to remove those margins without having to do it by hand.
Here's a link to an article that illustrates how to use design tools in Visual Studio 2010 to lay out a form without having to type any XAML. (Despite the title, it's about WPF.)
The first part of the article shows hard-coded pixels, but I've linked to the second part that shows how to lay out the controls without that hard coding.
Layout Techniques for Windows Form Developers
When I drop a control into a stackpanel, it doesn't add margins, it "flows" in with the rest.
The controls you drop onto the design surface have a margin by default because that's how it knows where it's placed. What I typically do is create a grid and set it's margin where I want it, then create columns and rows to put controls into. I drop in my other controls which will add margins which are usually not what I want. After I have all my controls into my grid, reasonably placed, I switch to XAML view and either remove the margin completely (which causes a control like a button to fill the entire space), or make the margin something like 5, which puts some nice padding around the control.
Bottom line...and this is especially true with Silverlight development, you must get used to manipulating the XAML directly. It's the only way you'll get the layout exactly where you want it. This is my opinion and most everybody in my shop who does WPF/silverlight development.
Unfortunately there does not appear to be a means to do this.
The default size is set as a result of you manipulating the size of your control is the designer. When you increase the width and/or height of a control the designer is interpreting your actions as a request to make the control that specified width and/or height.
A similar situation is encountered with the margins. As you alter the position of your control within the designer, it modifies properties to achieve the layout you've created. In the case of most containers the simplest solution is to modify margins in order to achieve the desired position, as you've already pointed out the simples solution is not always the most desired.
Personally I prefer to only use the XAML editor and only occasionally take a peak at the WPF Designer when I want to see the current layout. I also tend to favor using the Grid to layout most of my windows/controls as it provides the greatest flexibility not only for sizing and positioning, but for other tasks/features such as animations, transforms, etc.
The problem is fairly simple, but is best illustrated visually. Note that all screen shots are from the Visual Studio 2005 design surface. I've noticed no difference when I actually run the application.
Here is my user control (let's call this UC-1):
The buttons on the control are set to anchor to Bottom + Right.
Here is what it looks like when placed onto a particular parent user control (UC-A):
Please disregard the difference in colors and such. Some styling is done in the user control's constructor.
Notice the bottom of the control is getting clipped. The instance of the consumed control on the parent is set with a "FixedSingle" border. Notice also that the consumed control is taller than the original, indicating that the buttons bottom anchor settings are being respected, but are essentially overshooting where it should be.
To confirm this is definitely a problem on the parent control, notice another user control (UC-2) containing a data grid view when placed on the same parent:
Again, the instance of the consumed control is set with a "FixedSingle" border which helps illustrate the clipping. The datagrid is properly anchored to the Bottom Right. To reinforce the perplexity of this problem, here's the first user control (UC-1) when placed on a different parent user control (UC-B):
alt text http://i38.tinypic.com/2rnyjd0.png
Here's the second "consumed" control (UC-2) when consumed by a form:
Notice, no clipping this time.
I have spent many hours searching and experimenting to resolve this. I have exhausted the various settings of margins, padding, sizes (min/max), locations, anchors... etc. I can not for the life of me figure out why this one user control is causing child user controls to clip like this.
Another strange thing I noticed was that when I do an UNDO on the parent user control design surface (where the controls are misbehaving), the clipped user control instances actually shift location even though the undo action is unrelated to those controls. For example, if I make the main containing control larger, then undo, a couple of the child user controls jump up. They appear to move about as far as they are being clipped. Very suspicious.
Does anyone have any idea what is going on??
A very interesting problem!
Does your problem parent (UC-A) override any of the methods around sizing or client areas?
Or has UC-A got a negative value for the bottom value of Padding or Margin ?
Is there anything else docked at the bottom edge of UC-A? Perhaps, something that has a negative size?
Or, does UC-A set the constraints of its child controls? If the minimum height of the panel is forced too large, you would get this result.
Hope this is helpful! If not, is there any chance you post the source to UC-A ?
I was having the exact same problem and found your post while searching for a possible solution. Although I'm pretty sure that this is a bug in winforms, I found a bit of a workaround. Just put everything in your user control inside a panel, dock the panel to full, and do your anchoring inside the panel. This seems to alleviate the problem, although my button does tend up to show up at a slightly different size than it should in the parent control. Very weird. I compensated by making the button smaller in the designer, and it stretches wider by a few pixels in the parent control for some unknown reason. Hope this helps.
Assuming the parent control in question is not a standard .NET framework type, but a custom one, I'd guess that it is mixing up client and screen co-ordinates somewhere in it's logic. But that's just a guess.