Setting a location other than 0,0 when Dock=Fill - winforms

I have a TabControl and on each TabPage is a DataGridView control docked to fill its own TabPage. I don't know how, but the first grid has a Location set to 3,3 which gives it a nice margin (while still docking/filling as it should).
The other grids are set to Location = 0,0 and I can't get them to match the first grid. If you set the Location then Dock, the Location is reset to 0,0. If you Dock, then try and set the Location to 3,3 it reverts immediately to 0,0.

Have you checked the Padding settings on each TabPage and/or the TabControl? This might explain the location being set to 3,3 for the first grid.
Also check the Margin on each DataGridView control.

Related

WPF set image position on grid (not row and column)

Is there any way in WPF to set X and Y coordinates of an image relative to it's parent grid?
Not using the setRow or setColumn, but X and Y.
This is not what the Grid control is for, that's what Canvas does. What you can do is add a Canvas control that spans all rows and columns of the grid, and then use the Canvas.X and Canvas.Y attributes to set the position.
Try Margin property to create space around element.
Margin can be set in formats "Left, Top, Right, Bottom" (e.g. Margin="10,20,10,20") or "LeftAndRight,TopAndBottom" (e.g. Margin="10,20", equal to previous example) or just one value for all sides (e.g. Margin="10"). X and Y will be Left and Top.
Panels (Grid, StackPanel, etc) respect Margin settings.
XAML designer in Visual Studio uses Margin,Width and Height to locate elements in a fixed positions, when drag and drop controls from Toolbox ("nails" them to one place, not very nice for adaptive desing).
Using Margin,Width and Height together is similar to using Location and Size to position WinForms controls

WPF Stretch Middle Content in DockPanel or Stackpanel

How do I stretch the content in the middle section of a Stackpanel or Dockpanel. I know that a dockpanel will stretch the last item but I need to stretch the middle item. I know that I could use a grid with * for the middle section but I want to be able to set the left and/or right items as collapsed depending on my window size.
You should still use a DockPanel with LastChildFill setted.
Your DockPanel will stretch the last element you put in it, not the last one according to view.
So you can put the element you want to stretch in the last position and use DockPanel.Dock="Top/Bottom/Right/Left" on others one.

Take object "out of the document flow" in Silverlight, with the same effect as CSS Absolute Positioning?

When using Silverlight 4, is it possible to set an Image to an absolute position, and bring it out of the document flow, allowing it to be positioned freely of any grids etc?
With CSS you can set an element to use absolute positioning, and then it will be positioned absolute, based on the first relative parent above it.
I want to be able to place an Image, anywhere on the screen, above anything else on the page, but in Silverlight.
I tried absolute positioning (In the code behind) and it doesn't seem to be positioned correctly, it looks as though it defaults to both Horizontal Alignment and Vertical alignment as
"Centre"
CustomIcon.Source = new BitmapImage(new Uri("http://media.trueachievements.com/imagestore/0000149800/149834.jpg", UriKind.Absolute));
CustomIcon.SetValue(Canvas.LeftProperty, Pt.X);
CustomIcon.SetValue(Canvas.TopProperty, Pt.Y);
CustomIcon.Visibility = System.Windows.Visibility.Visible;
Pt is set correctly elsewhere (Checked this when Debugging).
The image is in the Xaml with the x:Name attribute set, and is set to Collapsed visibility by default.
Any ideas if it's possible to get the same effect I described (CSS) but using Silverlight 4?
The canvas Left and Top attached properties only have an effect if you actually add the control to an Canvas element.
Just add a Canvas element to your xaml as the last element in the "LayoutRoot" grid. You do not need to set its width or height nor should you set it Grid.Row or Column.
Now when you add items to this canvas they can be positioned anywhere.

Silverlight ScrollViewer initial horizontaloffset

I have a question regarding the setting of the HorizontalOffset-property (using the ScrollToHorizontalOffset method).
Upon starting my application, the content for the scrollviewer is dynamically created (i.e. I do not know its extent during design-time). I then want to set the horizontal offset of the scrollviewer control, however at that time its scrollable width is returned as 0. Calling UpdateLayout on the scrollviewer does not help either.
I am currently working around this issue by checking the ScrollableWidth property of the scrollviewer control in the rendering event and make a call to ScrollToHorizontalOffset as soon as ScrollableWidth > 0.
This works fine but leads to a short display of the wrong inital position, before in "rendering" the position is adjusted.
Is there anything I can do to force an update on the scrollviewer so that I can set its horizontal offset without this hassle?
Thanks in advance!
Set the opacity of the Content control in the scroll viewer to 0. When you've called ScrollToHorizontalOffset then set the content control's opacity to 1. That way no content is actually seen until its positioned correctly.
Scrollable Height/Width will be zero until the child content is loaded. Until then, it doesn't know how big it needs to be - thus the value of 0.

How to make WPF WebBrowser grow horizontally and vertically?

In WPF, we are using a WebBrowser control to view HTML content. When we place the control on our window, it grows horizontally with the window as it grows/shrinks. However, we have not found a way to make the control grow vertically with the window. We are looking for some sample code that will allow the WebBrowser WPF control to grow both vertically and horizontally with the window.
With WPF and wanting to grow with the window, the magical starting point is to set the Margin to 0 and avoid setting width and height. (You can have margin equal to another number, but start with zero and see how it looks first!)
Another option is to use a dock panel with last child fill set to true, where the web browser control is the last element (as you read down the page - it doesn't have to be the last element in the rendered UI.

Resources