Skip to content

Add DP MatchSizeWith to PackIcon#4042

Merged
Keboo merged 6 commits intoMaterialDesignInXAML:masterfrom
corvinsz:fix1216
May 2, 2026
Merged

Add DP MatchSizeWith to PackIcon#4042
Keboo merged 6 commits intoMaterialDesignInXAML:masterfrom
corvinsz:fix1216

Conversation

@corvinsz
Copy link
Copy Markdown
Member

Possibly fixes #1216

This adds a new dependency property MatchSizeWith to the PackIcon, so the icon can be linked to another FrameworkElement to automatically adapt it's height. This is useful to automatically size an icon which belongs to some text.
As @Keboo mentioned in the linked issue, there are some trade-offs to be made, which I don't think we can fully eliminate.

See MD spec here: https://m3.material.io/styles/icons/applying-icons (Using Material Symbols with typography)
image

The icons Height and Width are bound to the referenced FrameworkElement's ActualHeight to keep it rectangular.

Example usage:

<StackPanel Orientation="Horizontal">
  <materialDesign:PackIcon Kind="Person"
                           MatchSizeWith="{Binding ElementName=tbTitle}" />
  <TextBlock x:Name="tbTitle"
             Style="{StaticResource MaterialDesignHeadline2TextBlock}"
             Text="Edit Person" />
</StackPanel>

If we actually want something like this, and it merges, I will add a follow-up PR for more documentation (incl. MD3 example).

@mzy666888
Copy link
Copy Markdown
Contributor

good work

@Keboo
Copy link
Copy Markdown
Member

Keboo commented May 1, 2026

I like the change but perhaps a different name for the DP. Thoughts on ScaleToSizeOf?

@Keboo Keboo modified the milestone: 5.3.2 May 1, 2026
@corvinsz
Copy link
Copy Markdown
Member Author

corvinsz commented May 1, 2026

Sounds good. I renamed the property from MatchSizeWith to ScaleToSizeOf and also adjusted the tests name.

@Keboo Keboo added this to the 5.3.3 milestone May 2, 2026
@Keboo Keboo added the release notes Items are likely to be highlighted in the release notes. label May 2, 2026
@Keboo Keboo merged commit 4ccb265 into MaterialDesignInXAML:master May 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release notes Items are likely to be highlighted in the release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PackIcon styles matching text styles (width/height)

3 participants