Can I use xaml ApplicationResources with the MvvmCross application

I am trying to add several ApplicationResourcesto my application Xamarinthat usesMvvmCross

I currently have a file App.cs:

public class App : MvxApplication
{
    /// <summary>
    /// Initializes this instance.
    /// </summary>
    public override void Initialize()
    {
       this.CreatableTypes()
            .EndingWith("Service")
            .AsInterfaces()
            .RegisterAsLazySingleton();
        .....etc etc..
    }
}

Now I follow Working with Styles with Xaml for your application and got:

<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:mvvmcross="clr-namespace:Cirrious.MvvmCross.ViewModels;assembly=Cirrious.MvvmCross"
             x:Class="FieldStrikeMove.Core.App">
    <Application.Resources>
        <ResourceDictionary>
            <Style x:Key="TestStyle" TargetType="Label">
                <Setter Property="TextColor" Value="Green" />
            </Style>
        </ResourceDictionary>
    </Application.Resources>
</Application >

I also added a keyword partialto my class App.cs, but that says:

Partial declarations must not indicate different base classes

So i tried

<?xml version="1.0" encoding="utf-8" ?>
<mvvmcross:MvxApplication xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:mvvmcross="clr-namespace:Cirrious.MvvmCross.ViewModels;assembly=Cirrious.MvvmCross"
             x:Class="FieldStrikeMove.Core.App">
    <Application.Resources>
        <ResourceDictionary>
            <Style x:Key="TestStyle" TargetType="Label">
                <Setter Property="TextColor" Value="Green" />
            </Style>
        </ResourceDictionary>
    </Application.Resources>
</mvvmcross:MvxApplication>

but I get:

35 "FieldStrikeMove.Core.App" "TView" "Xamarin.Forms.Xaml.Extensions.LoadFromXaml(TView, System.Type)". 'FieldStrikeMove.Core.App' 'Xamarin.Forms.BindableObject'.

Xaml MvvmCross Xamarin

+4
2

, @Davids , App .

, ResourceDictionary ,

Application.Current.ResourceDictionary = new ResourceDictionary();
//add styles here

Xaml ResourceDictionary Xaml :

<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyApp.Styles">
  <Style x:Key="labelStyle" TargetType="Label">
    <Setter Property="TextColor" Value="Green" />
  </Style>
</ResourceDictionary>

MyApp.Styles Xamarin.Forms.ResourceDictionary

( Xamarin)

:

ContentPage My PCL:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyApp.Styles">
  <ContentPage.Resources>
    <ResourceDictionary>
      <Style x:Key="labelStyle" TargetType="Label">
        <Setter Property="TextColor" Value="Green" />
      </Style>
    </ResourceDictionary>
  </ContentPage.Resources>
</ContentPage>

MainActivity LoadApplication :

var styles = new Styles();
Xamarin.Forms.Application.Current.Resources = styles.Resources;
+6

, , , , . , Xamarin.Forms MVVMCross Xaml . , , . ResourceDictionary, , , , .

MvxApplication , , XAML, ResourceDictionary, , .

+2

Source: https://habr.com/ru/post/1609446/


All Articles