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

[Android] Update/Binding on BitmapImage does not update parent ImageBrush #7288

Closed
queequac opened this issue Oct 5, 2021 · 3 comments · Fixed by #12076
Closed

[Android] Update/Binding on BitmapImage does not update parent ImageBrush #7288

queequac opened this issue Oct 5, 2021 · 3 comments · Fixed by #12076
Assignees
Labels
difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform project/shapes-brushes 🔶 Categorizes an issue or PR as relevant to shapes and brushes

Comments

@queequac
Copy link
Contributor

queequac commented Oct 5, 2021

Current behavior

When using a BitmapImage as ImageSource for a ImageBrush, updates on the BitmapImage are not triggering updates on the brush.

Sample:

        <Grid x:Name="tile">
            <Border Width="48" Height="48" CornerRadius="8">
                <Border.Background>
                    <ImageBrush Stretch="UniformToFill" x:Name="brush">
                        <ImageBrush.ImageSource>
                            <BitmapImage UriSource="{x:Bind TileContent, Mode=OneWay}" DecodePixelType="Logical" DecodePixelWidth="48" DecodePixelHeight="48"/>
                        </ImageBrush.ImageSource>
                    </ImageBrush>
                </Border.Background>
            </Border>
        </Grid>

In the sample above, the UriSource is bound against a property of type Uri. Whenever the uri changes, the new image shall be loaded and the content of the ImageBrush should change.

While this works as expected under Windows, on Android only the initial BitmapImage will be created and any further change (via binding or set programmatically) will be ignored.
Obviously the ImageBrush does not realize the actual instance of its BitmapImage changed.

Expected behavior

Should behave like under Windows. Any change to the BitmapImage (e.g. by modifying the UriSource property) should also be reflected by the ImageBrush using the BitmapImage as its ImageSource.

How to reproduce it (as minimally and precisely as possible)

Use the snippet above and bind against a DependencyProperty. Switching the uri will change the image under Windows, while it will be created under Android once and not change afterwards.

Workaround

Instead of modifying the BitmapImage, under Android the ImageSource has to be set explicitly.
In my case I added code-behind:

        public MyControl()
        {
            this.InitializeComponent();
            this.RegisterPropertyChangedCallback(TileContentProperty, TileContentChanged);
        }

        private void TileContentChanged(DependencyObject sender, DependencyProperty dp)
        {
            BitmapImage bi = new BitmapImage();
            bi.DecodePixelType = DecodePixelType.Logical;
            bi.DecodePixelHeight = 48;
            bi.DecodePixelWidth = 48;
            bi.UriSource = LogoUri;

            brush.ImageSource = bi;
        }

Explicitly setting the ImageSource as a whole will make the ImageBrush realize that something on the underlying BitmapImage object changed.

Works on UWP/WinUI

Yes

Environment

Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia

NuGet package version(s)

Uno.UI version 3.10.11

Affected platforms

Android

IDE

Visual Studio 2019

IDE version

16.11.4

Relevant plugins

No response

Anything else we need to know?

No response

@queequac queequac added difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification labels Oct 5, 2021
@jeromelaban jeromelaban added project/shapes-brushes 🔶 Categorizes an issue or PR as relevant to shapes and brushes and removed triage/untriaged Indicates an issue requires triaging or verification labels Oct 6, 2021
@francoistanguay francoistanguay assigned ghost Mar 9, 2022
@francoistanguay
Copy link
Contributor

@iury-kc Probably related/similar to the other bug you're working on .You should take a look after.

@ghost ghost assigned teras Mar 10, 2022
@francoistanguay francoistanguay removed their assignment Mar 11, 2022
@ghost ghost changed the title Update/Binding on BitmapImage does not update parent ImageBrush Reprodu Mar 17, 2022
@ghost
Copy link

ghost commented Mar 17, 2022

Hi @queequac ! Do you mind to give more details about your issue?

I tried to reproduce the scenario, however, it doesn`t work with UWP also.
Only changing the Uri TileContent property doesn't update the ImageBrush on UWP as well.

@ghost ghost changed the title Reprodu Update/Binding on BitmapImage does not update parent ImageBrush Mar 17, 2022
@queequac
Copy link
Contributor Author

@iury-kc In my case it works like a charme and I am using this under UWP even in production.😅

Create a new blank UWP project (e.g. with Visual Studio 2022) and modify only the MainPage.xaml and MainPage.xaml.cs accordingly:

MainPage.xaml

<Page
    x:Class="ImageBinding.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ImageBinding"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <Border Width="48" Height="48" CornerRadius="8">
            <Border.Background>
                <ImageBrush Stretch="UniformToFill" x:Name="brush">
                    <ImageBrush.ImageSource>
                        <BitmapImage UriSource="{x:Bind TileContent, Mode=OneWay}" DecodePixelType="Logical" DecodePixelWidth="48" DecodePixelHeight="48"/>
                    </ImageBrush.ImageSource>
                </ImageBrush>
            </Border.Background>
        </Border>

        <Button VerticalAlignment="Bottom" HorizontalAlignment="Center" Margin="8" Click="OnChangeIt">Change TileContent property</Button>
    </Grid>
</Page>

MainPage.xaml.cs

using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace ImageBinding
{
    public sealed partial class MainPage : Page
    {
        public static readonly DependencyProperty TileContentProperty = DependencyProperty.Register(nameof(TileContent), typeof(Uri), typeof(MainPage), new PropertyMetadata(new Uri("https://cdn.pixabay.com/photo/2020/03/09/17/51/narcis-4916584_960_720.jpg")));

        public Uri TileContent
        {
            get { return (Uri)GetValue(TileContentProperty); }
            set { SetValue(TileContentProperty, value); }
        }

        public MainPage()
        {
            this.InitializeComponent();
        }

        private void OnChangeIt(object sender, RoutedEventArgs e)
        {
            TileContent = new Uri("https://cdn.pixabay.com/photo/2013/07/21/13/00/rose-165819_960_720.jpg");
        }
    }
}

Click the button at the bottom and it switches the narcis to the blue rose.

@carldebilly carldebilly added the platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform label Mar 17, 2022
@carldebilly carldebilly changed the title Update/Binding on BitmapImage does not update parent ImageBrush [Android] Update/Binding on BitmapImage does not update parent ImageBrush Mar 17, 2022
@ghost ghost assigned iurycarlos and unassigned ghost Feb 8, 2023
@Youssef1313 Youssef1313 self-assigned this Apr 25, 2023
jeromelaban added a commit that referenced this issue May 3, 2023
GitHub Issue (If applicable): closes #11673, closes #7288, closes #9533

<!-- Link to relevant GitHub issue if applicable. All PRs should be
associated with an issue (GitHub issue or internal), unless the change
is documentation related. -->

## PR Type

What kind of change does this PR introduce?
<!-- Please uncomment one or more that apply to this PR

- Bugfix
- Feature
- Code style update (formatting)
- Refactoring (no functional changes, no api changes)
- Build or CI related changes
- Documentation content changes
- Project automation
- Other... Please describe:

-->

## What is the current behavior?

<!-- Please describe the current behavior that you are modifying, or
link to a relevant issue. -->


## What is the new behavior?

<!-- Please describe the new behavior after your modifications. -->


## PR Checklist

Please check if your PR fulfills the following requirements:

- [ ] Docs have been added/updated which fit [documentation
template](https://github.com/unoplatform/uno/blob/master/doc/.feature-template.md)
(for bug fixes / features)
- [ ] [Unit Tests and/or UI
Tests](https://github.com/unoplatform/uno/blob/master/doc/articles/uno-development/working-with-the-samples-apps.md)
for the changes have been added (for bug fixes / features) (if
applicable)
- [ ] Validated PR `Screenshots Compare Test Run` results.
- [ ] Contains **NO** breaking changes
- [ ] Associated with an issue (GitHub or internal) and uses the
[automatic close
keywords](https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue).
- [ ] Commits must be following the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/#summary)
specification.

<!-- If this PR contains a breaking change, please describe the impact
and migration path for existing applications below.
     Please note that breaking changes are likely to be rejected -->

## Other information

<!-- Please provide any additional information if necessary -->

Internal Issue (If applicable):
<!-- Link to relevant internal issue if applicable. All PRs should be
associated with an issue (GitHub issue or internal) -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform project/shapes-brushes 🔶 Categorizes an issue or PR as relevant to shapes and brushes
Projects
None yet
7 participants