Skip to content

[Enhancement] Hot Reload: refresh references to modified resource #619

Open

Description

@etvorun

Consider following XAML

<x:Double x:Key="LabelFontSize">20</x:Double>
<Style x:Key="LabelStyle" TargetType="Label">
  <Setter Property="FontSize" Value="{StaticResource LabelFontSize}"/>
</Style>
<Label Text='Label with Style' Style="{StaticResource LabelStyle}"/>
<Label Text='Just label' FontSize='{StaticResource LabelFontSize}'/>

Consider user changing<x:Double x:Key="LabelFontSize"> from 20 to 40. For Hot Reload to work correctly two things should happen:

  1. ResourceDictionary should be updated with new entry.
  2. References to modified resource should be updated. This in turn can cause cascading updates like refreshing styled elements.

We need API for 2). That is after VS Hot Reload modifies RD entries it needs help refreshing references to it.
The proposed API can be like this:

namespace Xamarin.Forms.HotReload
{
  class HotReloadHelper
  {
      public void RefreshResourceReferences (ResourceDictinary dictionary, string key) {};
  }
}

To better understand the issue try following:

  1. Open attached solution in VS.
  2. Build and run.
  3. Click on "Change LabelFontSize resource" button.
    Note: existing labels did not change their color.
  4. Click on "Add label with new font size" button.
    Note: new labels have different font size.

XamarinApp1.zip

Activity

  1. added
    partner
    partner/ui-tools
    on Mar 30, 2021
  2. added
    p/2
    on Apr 6, 2021
  3. added
    area-tooling
    on Nov 5, 2021
  4. added this to the .NET 7 milestone on Apr 18, 2022
  5. added
    p/3
    and removed
    p/2
    on May 3, 2022
  6. added
    area-xaml
    and removed
    area-tooling
    on Jan 20, 2023
  7. added
    partner/hot-reload-xaml
    on Apr 28, 2023
  8. borrmann commented on Nov 2, 2023

    @borrmann
    Contributor

    will this be added at some point?
    Once strings are replaced with a resource file, Hot Reload does not work for any text inside the app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-xamlp/3partnerpartner/hot-reload-xamlpartner/ui-toolsproposal/opent/enhancement ☀️

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions