Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static resources declared in App.xaml are not applied #47

Closed
zbigniew-gajewski opened this issue Jun 16, 2018 · 6 comments
Closed

Static resources declared in App.xaml are not applied #47

zbigniew-gajewski opened this issue Jun 16, 2018 · 6 comments
Assignees
Labels
kind/bug Something isn't working

Comments

@zbigniew-gajewski
Copy link

zbigniew-gajewski commented Jun 16, 2018

Steps to reproduce:

  1. Clone this repository, restore nuget packages, rebuild.
  2. Run UnoTest.Web project (right click, start new instance) - clicking the button will increase the counter - OK.
  3. Change MainPage.xaml by adding DataContext attribute to the header:
<Page x:Class="UnoTest.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="using:UnoTest"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      mc:Ignorable="d"
      DataContext="{Binding MainPageViewModelInstance, Source={StaticResource Locator}}">
    
        <Grid  Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
...
</Page>

image

  1. In MainPage.xaml.cs remove (or comment) line creating a new instance of the MainPageViewModel class:
public sealed partial class MainPage : Page
{
        public MainPage()
        {
            InitializeComponent();
//            DataContext = new MainPageViewModel();
        }
  } 

image

  1. Rebuild the whole solution.

Result:
6. Run UnoTest.UWP project (right click, start new instance) - clicking the button will increase the counter - correct behavior after change.
7. Run UnoTest.Web project (right click, start new instance) - clicking the button will not increase the counter - bad behavior after change.

Expected result:
After running UnoTest.Web app, clicking the button should increase the counter.

@jeromelaban
Copy link
Member

This is a known issue for WASM, this works for iOS and Android.

The best workaround for now is to declare it in a merged resource dictionary.

@jeromelaban jeromelaban added platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform kind/bug Something isn't working labels Jun 16, 2018
@jeromelaban jeromelaban removed the platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform label Jul 11, 2018
@jeromelaban jeromelaban changed the title Wasm - static resources declared in App.xaml doesn't work. Static resources declared in App.xaml are not applied Jul 11, 2018
@carldebilly carldebilly self-assigned this Jun 19, 2019
@carldebilly
Copy link
Member

carldebilly commented Jun 19, 2019

I reproduced the problem and I found the cause... it's very far from the reported bug.

The actual cause

The Wasm version of MvvmLight will use the netstandard1.0 version of the package and the IoC in this version won't implement the IServiceLocator.

See those lines: https://github.com/nventive/uno.mvvmlight/blob/3408287579ace291c9519edefc8017df6a151aac/GalaSoft.MvvmLight/GalaSoft.MvvmLight.Extras%20(PCL)/Ioc/ISimpleIoc.cs#L38-L40

Since the project Uno.Core is compiled in netstandard2.0, it will include his own version of CommonServiceLocator (v1.3) as defined in this bug I just opened: unoplatform/Uno.Core#53

What is happening in the app

  1. The initial navigation to MainPage.xaml will be initiated

  2. In the MainPage.xaml InitializeComponent(), Uno will successfully resolve the Locator resource

  3. Uno will call the MainPageViewModelInstance property of ViewModelLocator

  4. This one will cast SimpleIoc.Default as IServiceLocator, which is not implemented this way

    Code here: https://github.com/zbigniew-gajewski/uno-wasm-aspnet-core/blob/78e9491427166d4a4242ddbec85e7080c38f51e9/UnoTest/UnoTest.Shared/ViewModels/ViewModelLocator.cs#L24

  5. A null-reference exception will terminate the initial navigation, leading to the false interpretation there's a problem with resources.

I will close this bug as not related to Uno directly (the real issue has been created in Uno.Core project). Feel free to reopen it or ask more details.

@carldebilly
Copy link
Member

Ooohhh... by the way, to find this problem I found those 2 assemblies must be removed from linker in the LinkerConfig.xml:

<assembly fullname="UnoTest.Wasm" />
<assembly fullname="GalaSoft.MvvmLight.Platform" />

@zbigniew-gajewski
Copy link
Author

  1. Thanks for diagnosing the bug.
  2. Unfortunately without <assembly fullname="UnoTest.Wasm" /> accessing data with BreezeSharp doesn't work, I mean, the list with received data is not displayed.

@carldebilly
Copy link
Member

When I said removed from linker, it means those lines must be added to the config file ;-)

Sorry for the confusion.

@zbigniew-gajewski
Copy link
Author

Aaa, OK :) Thanks.

jeromelaban added a commit to jeromelaban/uno that referenced this issue Nov 18, 2021
lukeblevins pushed a commit to lukeblevins/uno that referenced this issue Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants