Iconize icon indicating copy to clipboard operation
Iconize copied to clipboard

UWP: Icon and visibility not always being set correctly

Open csuzw opened this issue 6 years ago • 2 comments

I've got a problem where when navigating to a page the toolbar items are not displaying and no icon is displayed. Initially it displays correctly and always displays correctly after any properties that are bound to the IconToolbarItem change but at some point after the properties have been set on page load, it seems like something is changing and the XF Platform.UpdateToolbarItems() is being called and Iconize is not also getting notified so it never sets the icon or visibility. I'm not too familiar with the inner workings of XF/Iconize so I might be incorrect on the chain of events here.

I have tried to create simple app to reproduce this but so far have been unable to do so. Although this is happening consistently in some places in my app, in other it is fine and I have yet to be able to determine what the difference is. If I put a sufficiently long delay in and then force the toolbar items to update in some way then it's fine but this is terrible solution as I can't guarantee how long it is until this mystery event happens that messes it up.

I'm using Xamarin.Forms 3.4.0.1008975 and Xam.Plugin.Iconize.FontAwesome 3.4.0.103. Unfortunately I can't update XF currently, so can't update to the latest Iconize, however as far as I can see there hasn't been any change that would affect this unless it's in XF itself.

I was hoping that someone here who knows much more about the internals of this might be either be familiar with this issue or have an idea how I can track down the source of the problem?

csuzw avatar Feb 26 '19 18:02 csuzw

So I've just worked out what this is. I don't know if it's still a problem in the current version or not. Basically the Title on the toolbar is bound to a property which is getting set after everything else and when this happens, the buttons don't get rendered properly. I guess this is because Iconize's toolbar layout function is not being called when the Title changes.

csuzw avatar Feb 26 '19 21:02 csuzw

I ran into the same issue on version 3.5.0.123 of Iconize.

On my base page I ended up doing something similar to the following:

protected override void OnPropertyChanged(string propertyName = null)
{
    base.OnPropertyChanged(propertyName);
    if (Device.RuntimePlatform == Device.UWP &&
        propertyName == TitleProperty.PropertyName)
    {
        MessagingCenter.Send((object)ToolbarItems, "WhateverYouWant");
    }
}

I have a custom MasterDetailPageRenderer and in the constructor I have the following:

MessagingCenter.Subscribe<object>(this, "WhateverYouWant", OnUpdateToolbarItems);

https://github.com/jsmarcus/Iconize/issues/24 Is why I have a custom MasterDetailPageRenderer.

MattRames avatar Apr 16 '19 21:04 MattRames