locked
Static Resources with XAML Previewer RRS feed

  • Question

  • User220000 posted

    Someone got it to work with the XAML previewer ? Specially using Prism and App.xaml ?

    Wednesday, September 14, 2016 9:50 PM

Answers

  • User112369 posted

    Hi @jbravobr,

    After searching a bit, it seems that with the merged dictionary we can define resource dictionary and use XAML static resource:

    App.cs var resource = new ResourceDictionary(); resource.MergedWith = typeof(TestTheme); Resources = resource;

    TestTheme.xaml <?xml version="1.0" encoding="utf-8" ?> <ResourceDictionary x:Class="UsingModules.TestTheme" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <Style TargetType="Label"> <Setter Property="TextColor" Value="Blue" /> </Style> </ResourceDictionary> TestTheme.cs public partial class TestTheme { public TestTheme() { InitializeComponent(); } }

    I tested it on a simple project and it worked, I will try to use it with your solution next.

    Best, Min

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, October 4, 2016 2:31 PM

All replies

  • User226261 posted

    @MobileTeamIcatu i have used gorilla player (gorillaplayer.com/) and its worked fine on prism.

    Wednesday, September 14, 2016 11:49 PM
  • User70197 posted

    @PubuduGayan, we've already used Gorilla too. In fact we help the Gorilla team to fix it to work with Prism. We got a "fix"for now, we remove the App.xaml and use just App.cs and a Static Class for the Static Resources.

    Thanks!

    Thursday, September 15, 2016 3:04 AM
  • User112369 posted

    Hi @jbravobr,

    Can you please provide a bit more detail on this workaround? Does this mean you have to change all XAML resources manually into C# using Resource.Add() because it seems that ResourceDictionary cannot be refered to using a "key".

    Thanks!

    Tuesday, October 4, 2016 9:54 AM
  • User70197 posted

    Hi @minzhao

    After remove the App.xaml.cs an use only App.cs, you have to create an Generic Class. Have that one, you will declare it as a STATIC Class and create static properties for yours styles. Once you create that, in your XAML files you just need to declare a alias for the Namespace and Assembly, where this STATIC class is located and in yours controls use the Sytle TAG to apply the style like

    Look exactly here (https://developer.xamarin.com/guides/xamarin-forms/xaml/xaml-basics/xamlmarkupextensions/#ThexStaticMarkup_Extension) for a more detailed information

    Tuesday, October 4, 2016 10:06 AM
  • User112369 posted

    @jbravobr Thanks! I will try it now that was really fast :smiley:

    Edit: hmm.. so now only C# global static resource can be used right? Is there a way I can still reuse my previously declared XAML static resources.

    Tuesday, October 4, 2016 10:12 AM
  • User70197 posted

    Yes @minzhao, after this only C# global static resource can be used.

    Tuesday, October 4, 2016 10:19 AM
  • User112369 posted

    Hi @jbravobr,

    After searching a bit, it seems that with the merged dictionary we can define resource dictionary and use XAML static resource:

    App.cs var resource = new ResourceDictionary(); resource.MergedWith = typeof(TestTheme); Resources = resource;

    TestTheme.xaml <?xml version="1.0" encoding="utf-8" ?> <ResourceDictionary x:Class="UsingModules.TestTheme" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <Style TargetType="Label"> <Setter Property="TextColor" Value="Blue" /> </Style> </ResourceDictionary> TestTheme.cs public partial class TestTheme { public TestTheme() { InitializeComponent(); } }

    I tested it on a simple project and it worked, I will try to use it with your solution next.

    Best, Min

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, October 4, 2016 2:31 PM