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

Easy way to theme a page dynamically

$
0
0

I want to apply a bunch of styles to a page controls upon some data, for example, if current ViewMode is ReadOnly, the save button becomes hidden, and the Entrys are disabled, but if the ViewMode is New then the button becomes Visible and the Entrys are editable.

The pages I'm working on are full of controls, and much more complex than this axample, and currently what I do is that I apply DataTrigger for every control that is affected by the ViewMode , but this makes it hard to make changes to the code (maintainability).

so I thought if there is a better way to do this, for example having two styles, one for the New and another for Readonly modes, and the page picks the appropriate style and apply it to its controls, by binding some property on the ContentPage to the ViewMode and with a converter, the appropriate style is returned (or a DataTrigger).

I know this all is inapplicaple in XF, for example I'll have to create a style for every control, and the page may have two ResourceDictionarys and in code-behind I set only one ResourceDictionary based on the ViewMode.. but this is a lot of code for a simple purpose!

Any other better approach?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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