Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

How can I group styles inside something similar to a ControlTemplate and toggle between them

$
0
0

So I was going thru an example that showed how I can setup control templates and then to bindings to a ConttolView to make app wide changes, to a theme. All this is fine and dandy for controlling appearance in the Control Template.

  • My question is, is there a way to access the ControlPresenters children via a type ID such as label and apply a styling to it?

This is what I have implemented so far:- (Based on an example I picked up in a blog) bu Udara Alwins:
<?xml version="1.0" encoding="utf-8" ?>

<Application.Resources>

        <!--template theme 1-->
        <ControlTemplate x:Key="MyTemplate1">

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="0.1*" />
                    <RowDefinition Height="0.8*" />
                    <RowDefinition Height="0.1*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="0.05*" />
                    <ColumnDefinition Width="0.95*" />
                </Grid.ColumnDefinitions>

                <!--template header-->
                <!--use of template binding for color-->
                <BoxView Grid.ColumnSpan="2" Color="{TemplateBinding Parent.ThemeColor}" />
                <Label Grid.Row="0" Grid.Column="1"
     Text="this is my theme style 1"
     TextColor="White"
     VerticalOptions="Center" />
                <!--template header-->

                <!--your page content goes in here-->
                <ContentPresenter Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"  BackgroundColor="{TemplateBinding Parent.ThemeColor}">

                </ContentPresenter>

            </Grid>
        </ControlTemplate>

    </ResourceDictionary>
</Application.Resources>

  • My ultimate goal is to avoid having to use DynamicResouce in each and evey control throughout the app.
    • What I want to do is have somthing similiar to a CSS style sheet that can be swapped , with another style sheet to change the app's theme.
  • I do not want to have to go to each and ever labe, or picker or text box and make changes to add this dynamicResoure bingind.
  • If there is a way to somehow drive styling by hitting a custom renderet I am fine with that too,
  • Bottom line is , I want to somehow use whaever styles are defined in App.Xaml to drive the changes to the controls, without me having to go to each and every control and add the DynamicResource binding.

Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>