Why use XAML in visual studio express for windows 8? - xaml

i'm trying to do an application for Windows 8 and i'm following a guide on channel9.msdn
I cant understand why they use XAML to create textbox, label or other controls.
There's a reason ? There's a form which is much faster: simply drag & drop controls into the UI.
So why use XAML ?
Thanks all and sorry for my english :/

XAML supports laying out the form so that if you resize the window, the controls contained in the window are always consistently positioned according to the layout.
If you just drag and drop, you will see that the designers uses margins to position the controls. When you resize the window, they kind of keep the same position and are not going to be well positioned anymore.
This layouting is the essence of WPF. Just read a tutorial about layouting in WPF.

Drag and drop creation of UIs when using XAML creates very poorly formatted XAML and since there are a significant number of things which are most easily done in XAML (data templates for instance), it's easier to simply construct your UI in XAML from the start.

Related

Avalonia UI, creating a custom control by drawing things

One could create a control by starting from a container control (like panel) and add other existing controls (like buttons, textbox, etc) on it. But in some cases, there are no such suitable primitive controls and one has to draw things from scratch.
Avalonia UI's Visual Studio extension has a UserControl template, and it seems that it allows adding existing controls using XAML, which is the former case of the previous paragraph. But how to draw from scratch? Where is WinForm's OnPaint() equivalent or WPF's OnRender() equivalent? Is there any example of creating a control from scratch in Avalonia UI?
or WPF's OnRender() equivalent
It's called Render, the name is pretty much the only difference, DrawingContext's API closely resembles WPF one.

Custom button in Windows 8.1 app

I have a requirement to create a button in a Windows 8.1 app which has an icon and a text label. The icon will be a symbol from Segoe UI Symbols and the text label will be Segoe UI Semibold at a smaller text size.
I want to be able to reuse the button in different places within the app, using different icons and text labels.
How show I go about this? I could create a button and then edit the ContentPresenter to have a horizontally oriented stack panel with two TextBlocks, but then how could I reuse this? And how could I change the text in the two different text blocks?
Should I create a separate custom control with separate dependency properties for each of the textblock strings? I'm interested in hearing what you would do.
thanks
Create a simple Style. To make it easy, I would base it off the standardized AppBarButton style. You can format it to whatever size you want (I have done something similar to make a larger button or one with text on the side).
Have the main icon simply be a ContentPresenter which binds to the Content using a TemplateBinding. Make sure to set the FontFamily to Segoe UI Symbol. Have the text label pull from AutomationProperties.Name, similar to how the AppBarButton style does.
Then, whenever you want to use this just do:
<Button Style="{StaticResource MyCustomButtonStyle}"
Content="" // Where "000" is replaced by the number of the icon you wish to use.
AutomationProperties.Name="Text Label"/>
This should be extensible and easily reproducible to whatever location you need. When copying over the AppBarButton style, I suggest removing the artificial size limits (specifically the width of the main content Grid). I do suggest either giving the Text Label a fixed size or having it pull its size from the specified parent Width, so that it will Wrap correctly.
Hope this helps and happy coding!
Are you desiring to create something like for an AppBar? Take a look at AppBarButton and the style/types it supports. In Windows 8.1 we added some things around SymbolIcon specifically. Since you basically want two pieces of 'content' for your style you'll have to re-purpose one property (unless you create a custom control which doesn't sound needed for this scenario). Using AutiomationProperties.Name for the visible label is a good idea because it will also help with accessibility by default for those users.
Investigate the style for AppBarButton to get you started.

Content control for complex layout

I start to learn winrt so I have question regarding containers in xaml.
I want to have on main screen of my app a set of different custom controls, but i want to have such interface like in Gridview (Horizontal scrolling, names for groups).
Yes, I can use GridView with different templates per item. But it's not a good solution.
For better explanation please review my picture. It's my goal.
How can I do this? Should i write some kind of custom GridView or there is already such or similar controls?
Thank you!
You can achieve this by using the following:-
-Scroll Viewer
- StackPanel (orientation horizontal)
-Grid view
-User Control
-...
If you are targeting 8.1 then you can use the new hubs which are designed exactly for the described scenario.

Is there a WrapPanel (not WrapGrid) control in WinRT-XAML?

A XAML StackPanel aligns controls side-by-side in a single direction. A WrapPanel is similar but like TextWrapping="Wrap" in a XAML TextBox the controls "wrap" to the next column or row when the respective height or width is reached.
Similar, but not the same, WrapGrid wraps content, but in a uniform grid. Though the VariableSizedWrapGrid allows for dissimilar items in the container. Neither of the WrapGrids can be used outside of an ItemsControl. So, they are disqualified.
When developers look in their native XAML Toolbox in Visual Studio there is no WrapPanel. WPF developers had a WrapPanel so they might be looking for this common tool to solve their scenario. So, I have to ask:
Does anyone know of a WrapPanel in XAML-WinRT? (what about one that is virtualized?)
There is one in WinRT XAML Toolkit here. It was ported from Silverlight Toolkit.
I had a same requirement and after googled it for a while, I've decided to use custom control for this. Please find following link for implementation:
http://www.codeproject.com/Articles/463860/WinRT-Custom-WrapPanel
Hope this will help you.

Rotate Windows Store XAML control using an custom Panel

I am using a custom Panel, very similar to a radial panel.
I was wondering if there was a way to rotate the items as well as position them.
I know I could use different item templates, but that would require assigning the templates during coding. I'm looking for a runtime solution.
Any ideas?
What I did was create an item template that rotates the item based on a data bound property in the CLR object.
In order to rotate in a windows store app, I used a modified LayoutTransformer