Skip to content

DependencyProperties precedences storage is wrong [7.0] #16356

Closed

Description

@carldebilly

Current behavior

The current precedences mechanism is not following its own logic, especially when applying values coming from default style (defined in generic.xaml), implicit style (keyless resolved through resource dictionaries) and explicit style (keyed style referenced directly on the element).

TLDR

The default style is always saved under the ImplicitStyle precedence and the applied style (implicit or explicit) is saved under the ExplicitStyle precedence.

Observed result

Building the following code:

public sealed partial class MyControl : Control
{
    // Register a DependencyProperty "MyProperty" of type string
    public static readonly DependencyProperty MyPropertyProperty
        = DependencyProperty.Register("MyProperty", typeof(string), typeof(MyControl), new PropertyMetadata("Default Metadata Value")
    );

    public string MyProperty
    {
        get => (string)GetValue(MyPropertyProperty);
        set => SetValue(MyPropertyProperty, value);
    }

    public MyControl()
    {
        DefaultStyleKey = typeof(MyControl);

        MyProperty = "Local Value";
    }
}

In generic.xaml:

  <Style TargetType="local:MyControl">
    <Setter Property="MyProperty" Value="Default from Generic.xaml" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="local:MyControl">
            <TextBlock Text="{TemplateBinding MyProperty}" />
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

In app.xaml (AppResources.xaml)

  <Style TargetType="local:MyControl" x:Key="MyControlStyle">
    <Setter Property="MyProperty" Value="Explicit Style Value" />
  </Style>

  <Style TargetType="local:MyControl" x:Key="MyControlImplicitStyle">
    <Setter Property="MyProperty" Value="Implicit Style Value" />
  </Style>

  <Style TargetType="local:MyControl" BasedOn="{StaticResource MyControlImplicitStyle}" />

Used like that in the MainPage.xaml:

  <StackPanel
        HorizontalAlignment="Left"
        VerticalAlignment="Center"
        Padding="100, 20"
        Spacing="20">

    <VisualStateManager.VisualStateGroups>
      <VisualStateGroup x:Name="CommonStates">
        <VisualState x:Name="NormalState" />
        <VisualState x:Name="AlteredState">
          <Storyboard>
            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="my" Storyboard.TargetProperty="MyProperty">
              <DiscreteObjectKeyFrame KeyTime="0" Value="Value from VisualStateManager" />
            </ObjectAnimationUsingKeyFrames>
          </Storyboard>
        </VisualState>
      </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>

    <local:MyControl x:Name="my" MyProperty="XAML Value (explicit)" Style="{StaticResource MyControlStyle}" />
    <TextBlock x:Name="result"></TextBlock>
  </StackPanel>

Observed Result

Precedence Observed Value
Coercion (unset)
FillingAnimations (unset)
Animations Value from VisualStateManager
Local XAML Value (explicit)
TemplatedParent (unset)
ExplicitStyle Explicit Style Value
ImplicitStyle Default from Generic.xaml
Inheritance (unset)
DefaultStyle (unset)
DefaultValue Default Metadata Value

Expected behavior

Expected Result

Precedence Observed Value
Coercion (unset)
FillingAnimations (unset)
Animations Value from VisualStateManager
Local XAML Value (explicit)
TemplatedParent (unset)
ExplicitStyle Explicit Style Value
ImplicitStyle Implicit Style Value (!!)
Inheritance (unset)
DefaultStyle Default from Generic.xaml (!!)
DefaultValue Default Metadata Value

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

No response

Workaround

No response

Works on UWP/WinUI

No

Environment

Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia

NuGet package version(s)

Uno 5.1

Affected platforms

WebAssembly, Android, iOS, macOS (AppKit), Mac Catalyst, Skia (WPF), Skia (GTK on Linux/macOS/Windows), Skia (Linux Framebuffer)

IDE

No response

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

Activity

  1. added
    kind/bug
    triage/untriaged
    difficulty/tbd
    on Apr 18, 2024
  2. Youssef1313 commented on Apr 18, 2024

    @Youssef1313
    Member

    Yup. We're taking this as a breaking change in Uno 6. See #15684

    There shouldn't be any bugs caused by this though. Just wrong terminology being used.

    Note that the precedences enum isn't intended for public access, even if it's public.

  3. added
    kind/breaking-change 💥
    on Apr 18, 2024
  4. self-assigned this
    on Apr 18, 2024
  5. changed the title [-]DependencyProperties precedences storage is wrong[/-] [+]`DependencyProperties` precedences storage is wrong[/+] on Jul 16, 2024
  6. added
    difficulty/starter 🚀
    and removed
    triage/untriaged
    difficulty/tbd
    on Jul 16, 2024
  7. added theissue type on Jun 20, 2025
  8. github-actions commented on May 3, 2026

    @github-actions
    Contributor

    This issue has had no activity for 120 days. It will be closed in 10 days if there is no further activity. Remove the Stale label or leave a comment to keep it open.

  9. added
    stale
    on May 3, 2026
  10. removed
    stale
    on May 4, 2026
  11. self-assigned this
    on Jul 2, 2026
  12. added this to the Platform 7.0 milestone on Jul 27, 2026
  13. MartinZikmund commented on Aug 3, 2026

    @MartinZikmund
    Member

    Audit result: DONE in feature/breakingchanges (as of 43acbf69dd).

    DependencyPropertyValuePrecedences has been realigned onto WinUI's BaseValueSource model, so the mismatch described here — the default style stored under ImplicitStyle and the applied style stored under ExplicitStyle — no longer exists. The fix intentionally does not implement the "Expected behavior" table verbatim; see the scope note below.

    • Enum surface — src/Uno.UI/UI/Xaml/DependencyPropertyValuePrecedences.cs now declares Coercion, Animations, Local, Style, BuiltInStyle, Inheritance, DefaultValue. ExplicitStyle → Style (WinUI BaseValueSourceStyle), ImplicitStyle/DefaultStyle → a single BuiltInStyle (WinUI BaseValueSourceBuiltInStyle), and the reader-less TemplatedParent level was removed.
    • Ordering corrected — BuiltInStyle now sits above Inheritance, documented in the XML remarks on the member.
    • All readers repointed — DependencyObjectStore.cs:2227/2233/2263, FrameworkElement.cs:515 and :687, Style/Style.cs:128-180, Internal/DependencyPropertyHelper.cs:169-176, DependencyObjectExtensions.cs:415-417, WrapPanel.cs:17, Slider.mux.cs:693, SampleControl.cs:64. Grepping the branch for Precedences.ExplicitStyle|ImplicitStyle|DefaultStyle|TemplatedParent returns no code hits.
    • Scope deviation (deliberate) — the issue's expected table asks for three distinct style slots; the delivered model collapses explicit + implicit into one Style level, because WinUI's BaseValueSource has no such split (PropertySystem.cpp / PropertyChainEvaluator.cpp expose only BaseValueSourceStyle and BaseValueSourceBuiltInStyle and handle them identically), and FrameworkElement.UpdateActiveStyle() applies exactly one style. That matches @Youssef1313's triage above — wrong terminology, not a behavioural bug.
    • API-diff bookkeeping — build/PackageDiffIgnore.xml:2312-2315 records all four removed members (TemplatedParent, ExplicitStyle, ImplicitStyle, DefaultStyle), each with a #16356 reason.
    • Tests — src/Uno.UI.UnitTests/DependencyProperty/Given_DependencyProperty.cs adds When_Each_Precedence_Set_Then_Highest_Wins (line 434) and When_BuiltInStyle_Set_Then_Takes_Precedence_Over_Inherited_Value (line 468); the runtime test Given_DependencyPropertyHelper.cs:223 asserts Precedences.Style.

    Fixed by #23685

    Cosmetic follow-up only, no functional impact: two comments still name removed members — src/Uno.UI/UI/Xaml/Documents/TextElement.cs:388 and src/Uno.UI.UnitTests/DependencyProperty/Given_DependencyProperty.cs:1765. Also note the PR targeted feature/breakingchanges, so its closes #16356 will not auto-close this issue — it needs a manual close.

    Audit is code inspection against the branch worktree; no build or runtime validation was performed.

  14. changed the title [-]`DependencyProperties` precedences storage is wrong[/-] [+]`DependencyProperties` precedences storage is wrong [7.0 ][/+] on Aug 9, 2026
  15. changed the title [-]`DependencyProperties` precedences storage is wrong [7.0 ][/-] [+]`DependencyProperties` precedences storage is wrong [7.0][/+] on Aug 9, 2026
  16. MartinZikmund commented on Aug 27, 2026

    @MartinZikmund
    Member

    Audit result: DONE in feature/breakingchanges (as of 0950717a0d7).

    Re-verified against the current tip; every claim in the 2026-08-13 audit round still holds byte-for-byte — same line numbers, same enum shape, same write/read sites, same tests. DependencyPropertyValuePrecedences is realigned onto WinUI's BaseValueSource model, so the mismatch described in the issue — the default style stored under ImplicitStyle and the applied style stored under ExplicitStyle — no longer exists.

    Landed

    • Enum surface — src/Uno.UI/UI/Xaml/DependencyPropertyValuePrecedences.cs:7-46 declares Coercion, Animations, Local, Style, BuiltInStyle, Inheritance, DefaultValue. ExplicitStyle → Style (documented <remarks>Corresponds to WinUI's <c>BaseValueSourceStyle</c>.</remarks> at :27), ImplicitStyle/DefaultStyle → a single BuiltInStyle (:32-37, Corresponds to WinUI's BaseValueSourceBuiltInStyle), and the reader-less TemplatedParent level is gone entirely.
    • Ordering corrected — BuiltInStyle (ordinal 4) sits above Inheritance (ordinal 5) in declaration order, with the XML remarks at :34-36 explicitly stating "This takes precedence over inherited property values so that setters not covered by an applied style are still honored" — the (!!) row from the issue's expected table.
    • Write sites correct — src/Uno.UI/UI/Xaml/FrameworkElement.cs:493 writes the applied style (explicit or implicit) at DependencyPropertyValuePrecedences.Style (OnStyleChanged(oldActiveStyle, _activeStyle, DependencyPropertyValuePrecedences.Style)); FrameworkElement.cs:665 writes the Generic.xaml default style at DependencyPropertyValuePrecedences.BuiltInStyle inside ApplyDefaultStyle().
    • No stale readers — grep -rn "Precedences\.\(ExplicitStyle\|ImplicitStyle\|DefaultStyle\|TemplatedParent\)" src/ returns 0 hits anywhere in src/.
    • API-diff bookkeeping — build/PackageDiffIgnore.xml:2397-2398 (and surrounding block) records the removed/renamed members with #16356 reasons, e.g. <Member fullName="Microsoft.UI.Xaml.DependencyPropertyValuePrecedences Microsoft.UI.Xaml.DependencyPropertyValuePrecedences::TemplatedParent" reason="Removed unused TemplatedParent precedence (#16356, breaking changes for 7.0)" /> and the ExplicitStyle→Style rename entry immediately below it.
    • Tests — src/Uno.UI.UnitTests/DependencyProperty/Given_DependencyProperty.cs:434 (When_Each_Precedence_Set_Then_Highest_Wins) and :468 (When_BuiltInStyle_Set_Then_Takes_Precedence_Over_Inherited_Value); runtime test src/Uno.UI.RuntimeTests/Tests/Uno_Helpers/Given_DependencyPropertyHelper.cs:223 asserts precedence.Should().Be(DependencyPropertyValuePrecedences.Style).

    Landed via #23685 (merge commit 004885fda6, confirmed an ancestor of HEAD via git merge-base --is-ancestor 004885fda6 HEAD).

    Caveats (not blocking)

    • Two comments still name the removed precedence terms and were not updated with the rest of the code: src/Uno.UI/UI/Xaml/Documents/TextElement.cs:385 ("we set this with ImplicitStyle precedence") and src/Uno.UI.UnitTests/DependencyProperty/Given_DependencyProperty.cs:1765 ("PropB should be on the ExplicitStyle value"). Cosmetic only — no code reads those literal names, confirmed by the zero-hit grep above; unchanged since the last audit round.
    • The PR targeted feature/breakingchanges, so its closes #16356 never auto-closed this issue on GitHub; it was closed manually.

    Audit is code inspection against the branch worktree; no build or runtime validation was performed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

difficulty/starter 🚀kind/breaking-change 💥kind/bug

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions