winrt xaml PageLayout VisualState - xaml

I have a lot of UserControls placed on my Page. All of them are in grid rows and colums. Also there are several nested grids that contain UserControls.
But now I need to provide Snapped VisualState with these UserControls but with completely different layout.
It is easy to select inner styles for UserControls but it is not clear for me how can I change for instance Grid.RowDefinitions with 2 rows to Grid.RowDefinitions with 3 rows, change every Grid.Row property for inner UserControls and even more to replace some childs elements from one grid to another.
Is it possible to make some Template for Grid elements?

After some struggles trying to dynamically layout and restyle controls depending on view state I decided to use the template approach and simply have separate views for different... views. Basically have separate logical tree for each view and switch visibilities of these depending on view state.

Related

How do you properly position elements in XAML without using absolute position?

I have a UWP app that I am working on, and using absolute position creates problems when using the app on screen sizes different than the one it was designed for.
I'm not sure how exactly i should place elements at distances from each other without using margin and absolute position. How should I be doing this?
Edit: I am using XAML to design the UI.
Well, it depends on what UI you want to build up.
There are various panels and, usually, there is NO need to use absolute position in most cases.
Usually, the Grid panel is used to create flexible layouts, by adding rows and columns: for example, if you want to create a page with some content and a bottom app bar with buttons on it, you usually create a Grid with as many rows as you need for your content controls, plus one for the bottom appbar itself.
Years ago, I also started building UIs by using absolute position for every element, but then times passes and you start having a flexible mind in order to build flexible layouts.
Sorry to not answer any further, but your question is just TOO broad to give any precise answer.
Best regards
How do you properly position elements in XAML without using absolute position?
You should use an appropriate layout panel:
Layout panels are containers that allow you to arrange and group UI elements in your app. The built-in XAML layout panels include RelativePanel, StackPanel, Grid, VariableSizedWrapGrid, and Canvas.

Creating hub page with different controls in Windows 8

The most landing/hub pages you see are just a GroupedGridView ( for example the actual marketplace app )
But I would like to have a Grouped hub page with different controls.
For example my first control is a ListView that contains some categories.
2nd and 3th control are GridViews with several items in them.
If all 3 controls were GridViews I could easily get this working but it's not.
I can't seem to find a working combination of ScrollViewer with a Grid or Stackpanel to get the actual full Horizontal Scrolling working.
Any idea's or examples on how to create such a landing/hub page with different controls in one horizontal page?
You can use an GridView that is not grouped where each item will be a different control displayed using a different DataTemplate.
Or you can trick the FlipView to behave like a Panorama control for Windows Phone. Details at http://dotnetbyexample.blogspot.cz/2012/08/a-winrt-behavior-to-turn-flipview-into.html
EDIT:
For the first solution you create a base class and create a list with your different objects derived from the base class. Then you use the GridView's ItemTemplaceSelector to select a select an appropriate DataTemplate. See http://coding.kulman.sk/using-different-data-templates-with-gridview-in-windows-8-apps/

Is preparing Windows 8 XAML HubPages from several GridViews inside ScrollViewer the good approach?

I'd like to get the effect visible on the picture:
I don't think it is. A GridView already has a ScrollViewer in itself, so multiple of them does not make sense. I would try to use a single GridView with GroupStyleSelector/ItemContainerStyleSelector/ItemTemplateSelector implementations and DataTemplates to define each item. A less dynamic version might just be a ScrollViewer with Style set to HorizontalScrollViewerStyle, a horizontal StackPanel and a few VariableSizedWrapGrids - if you bind the GridView to some groups or other panels to define the content.
This looks like a good sample based on the description (though the images seem to be missing for me).

two nearly identical usercontrols with different resize behavior

I have an application which has a tabcontrol that contains two tabpages. I have a custom made usercontrol docked to fill up each of those tabs. When I resize my main form to the minimum size allowed one tab resizes accordingly while the other seems to overflow the area and a couple ui items slip out of access/view.
One usercontrol was quite literally copied from the other and renamed and fields adjusted. The usercontrol size is the same between the two. Within the usercontrols there is a datagridview and a large panel full of textboxes and they have identical sizes and identical anchoring properties and even the same location coordinates.
I'm struggling to find a difference between the two but I really would like the resize behavior to match between the two usercontrols. I was wondering if anyone would have ideas of other things to check I did not mention here?
This should like very odd behavior.
There are a few things that I can think of to check:
1) Double-check that the user control is actually on the tab page itself and not on a different control, such as the tab or a common tab area (not sure of the tab control you are using; some controls have a common area that is available to all tabs).
2) Verify that the Dock property is indeed set to fill on the "bad" usercontrol.
3) Verify that you are not resizing or changing the Dock property on the bad usercontrol in code.
Found a minimum size on one of the usercontrols and that was the cause of my issue. Don't know how I didn't see it earlier.

Adding visible elements to a custom Panel in Silverlight 3

As I understand it, a Panel isn't meant to have any visible "chrome." The StackPanel, Grid and Canvas don't have any visible elements (with the exception of the gridlines, which they say are only for debugging layout.)
In my example, I am going to create a Custom Panel that uses Attached Properties to lay out its children controls. However, I want my Custom Panel to present a visible "grid" of sorts in the background. The look of the grid (sizing and positioning) will depend on the size and position of the child elements.
What are some of the ways to achieve this? Being very new to Silverlight and XAML in general, my first guess was to create a Custom Control which includes my custom panel for layout.
I think I'll be able to figure out the specific code, but I need to be pointed in the right direction in terms of what building blocks are appropriate for this scenario.
You are correct that custom Panels cannot show any extra chrome; they can only display their Children (Grid being an exception).
To do what you want to do, you could create a custom Panel which just adds extra Children to display the chrome. This would not be a good design though (since users of the Panel would see these extra items in the Children collection).
The best idea is to do what you said: create a custom Control that exposes a Children property. This control could internally use a private custom Panel to lay out these elements (e.g. TabControl uses a special TabPanel for laying out the tabs). In the Controls default template, you might want to use TemplateBinding on the Panels' Children property to your Control's Children property.
Panel can add Adorners to its children, read this article about adorners: http://msdn.microsoft.com/en-us/library/ms743737.aspx