Page 51 - MSDN Magazine, September 2018
P. 51
extra space around them. There are self-explanatory values such as Start, Center and End, as well as more granular options. These include SpaceAround, where elements are spaced with one unit of space at the beginning and end, and two units of space between them, so the elements and the space fill the line, and SpaceBetween, where child elements are spaced with equal space between units and no space at either end of the line, again so the elements and the space fill the line. The SpaceEvenly value causes child elements to be spaced so the same amount of space is set between each element as there is from the edges of the parent to the beginning and end elements.
CSS styles in Xamarin.Forms can be declared and consumed in different ways.
Within child views, you can set the FlexLayout.AlignSelf attached property to specify how the view should be aligned inside the axis of the FlexLayout. This is an object of type FlexAlignItems and pos- sible values are Auto, Start, Center, End and Stretch. The complete documentation for the FlexLayout control is available at bit.ly/2LaMzgt. Another interesting addition is support for Cascading Style Sheets (CSS), though it’s worth mentioning that CSS styles must be compliant
to Xamarin.Forms to be consumed in mobile apps (see bit.ly/2miMcSO) and that not all CSS styles are supported. Therefore, this feature should be considered a complement to XAML styles, rather than a replacement. Also, CSS styles are parsed and evaluated at runtime, not at build time.
CSS styles in Xamarin.Forms can be declared and consumed in different ways. One option is within a StyleSheet tag to be added as a resource in a page, like in the following snippet:
<ContentPage.Resources> <ResourceDictionary>
<StyleSheet> <![CDATA[ ^contentpage {
background-color: lightgray; } stacklayout {
margin: 20; } ]]>
</StyleSheet> </ResourceDictionary>
</ContentPage.Resources>
The content of the CSS is enclosed in a CDATA section. For each visual element, you provide the desired property/value pairs. Another option is to consume an existing style from a .css file, as follows:
<ContentPage.Resources> <ResourceDictionary>
<StyleSheet Source="/Assets/mystyle.css" /> </ResourceDictionary>
</ContentPage.Resources>
Remember that the .css file must be bundled with your applica- tion by setting its Build Action property as EmbeddedResource. CSS styles can also be declared and consumed in C# code. The following snippet shows how to declare and add a style to a page’s resources:
SUPER-FAST AND ADVANCED CHARTS
LightningChart®
Ÿ WPF and WinForms
Ÿ Real-time scrolling up to 2 billion points in 2D Ÿ Hundreds of examples
Ÿ On-line and off-line maps
Ÿ Advanced Polar and Smith charts Ÿ Outstanding customer support
2D charts - 3D charts - Maps - Volume rendering - Gauges
TRYFFORR
www.LightningChart.com/ms
FREEE