fix: #1341: MenuItem template binding error#1343
Merged
pomianowski merged 3 commits intolepoco:mainfrom Feb 16, 2025
Merged
Conversation
Use more efficient `{TemplateBinding}` for `MenuItem` templates, which also fixes the incorrect `{Binding Path}` syntax for attached properties.
chucker
approved these changes
Feb 16, 2025
Collaborator
chucker
left a comment
There was a problem hiding this comment.
(Nit: the description is no longer accurate.)
pomianowski
approved these changes
Feb 16, 2025
pomianowski
pushed a commit
that referenced
this pull request
Feb 16, 2025
* fix: #1341 Use more efficient `{TemplateBinding}` for `MenuItem` templates, which also fixes the incorrect `{Binding Path}` syntax for attached properties. * fix: set `StaysOpenOnClick` on screen-reader `TextBlock` * fix: Remove unnecessary TextBlock from MenuItem template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use more efficient
{TemplateBinding}forMenuItemtemplates, which also fixes the incorrect{Binding Path}syntax for attached properties.Pull request type
What is the current behavior?
Currently, at runtime when debugging, while using
MenuItem, the following error is seen in the Output Window:Issue Number: Fixes #1341
What is the new behavior?
The binding has been corrected to use
{TemplateBinding}instead of the{Binding}with the path specified incorrectly for attached properties.The previous template had these bindings:
Width="{Binding Width, RelativeSource={RelativeSource AncestorType={x:Type MenuItem}}}" Height="{Binding Height, RelativeSource={RelativeSource AncestorType={x:Type MenuItem}}}" Text="{Binding AutomationProperties.Name, RelativeSource={RelativeSource AncestorType={x:Type MenuItem}}}"Firstly, the
{Binding Path}syntax for attached properties would have beenPath=(Automation.Text), with parenthesis.Secondly, a more efficient
RelativeSourcewould have been{RelativeSource TemplatedParent}.Finally, switching to a
{TemplateBinding}is the most efficient binding, and it uses simplerPathsyntax.The new template changes these bindings as follows:
Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" Text="{TemplateBinding AutomationProperties.Name}"Other information
{Binding}withRelativeSource={RelativeSource TemplatedParent}is only appropriate in the case when the non-typical binding properties are needed, such asMode=TwoWay. The impliedModefor{TemplateBinding}is 'Mode=OneWay`.I verified that there were no other such
XAMLerrors in the commit e55d7d7 from @Difegue that introduced this bug.