Skip to content

Conversation

@zadjii-msft
Copy link
Owner

This adds a magic helper to load icons for us. Any time you want an icon, just do this:

<Border Width="16"
        Height="16"
        Margin="4,4,4,4">
    <Interactivity:Interaction.Behaviors>
        <cmdpalUI:LoadIconBehavior Source="{x:Bind ViewModel.PrimaryAction.Icon, Mode=OneWay}"/>
    </Interactivity:Interaction.Behaviors>
</Border>

And that'll magically give us a border filled with the icon, and updating with the binding.

I believe it'll also work with IRandomAccessStreamReferences, but I didn't actually test that with #151 yet.

I didn't actually implement the "caching" bit of this yet. That'll involve doing some locking per-key inside the factory and I didn't want to futz with that in this initial PR to restore icons

@zadjii-msft
Copy link
Owner Author

Icons:
image

Icons in the ...
image

Icons on the Tags
image

(icons in the Details doesn't work on this branch, because Details weren't implemented in this branch)

Copy link
Collaborator

@michael-hawker michael-hawker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, couple of questions, mostly about ensuring we don't leak the DispatcherQueue and tempt folks 😋

Will defer to @niels9001 on any notes about style/re-usability of the pattern for the icon with the Border. Probably not heavy enough that we'd want to stick it in a UserControl and deal with that overhead, I'm assuming? I do like the nice encapsulation we have in the cases where it's optional and we toggle visibility with HasIcon.

Comment on lines +47 to +48
// For inexplicable reasons, FontIconSource.CreateIconElement
// doesn't work, so do it ourselves
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's surprising! Is there an open issue for this in the WinUI repo?

I know there was some weird discussion around resourcing and the XAML tree recently, but think that was for Geometrys, but I wonder if there'd be some other odd shared reference with the font info/glyph maybe, who knows.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing that I found. I'm not sure if it's a platform bug or a "I'm holding it wrong" thing. IIRC it did end up returning an icon, but it never made it into the UI tree? 🤷

<!-- LoadIconBehavior will magically fill this border up with an icon -->
<Interactivity:Interaction.Behaviors>
<local:LoadIconBehavior Source="{x:Bind ViewModel.Details.HeroImage, Mode=OneWay}"/>
<local:HideMissingIconBehavior Source="{x:Bind ViewModel.Details.HeroImage, Mode=OneWay}"/>
Copy link
Collaborator

@michael-hawker michael-hawker Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline, this is a bit overzealous use of behavior here. We can expose a loading prop on the LoadIconBehavior, or just use the HasIcon on the VM at the moment like we did elsewhere for now.

Maybe later too, we just have a default icon that gets returned in the failure case in case devs are loading from remote resources?

(If we wanted to combine the HasIcon and HasLoaded we could bind them together with an x:Bind function on the parent border.)

Copy link
Collaborator

@michael-hawker michael-hawker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zadjii-msft zadjii-msft merged commit 6a7a244 into main Dec 10, 2024
@zadjii-msft zadjii-msft deleted the dev/migrie/f/icon-factory branch December 10, 2024 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants