Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Support DependencyPropertyKey and RegisterReadOnly as in WPF #3139

Open
robloo opened this issue Aug 16, 2020 · 4 comments
Open

Proposal: Support DependencyPropertyKey and RegisterReadOnly as in WPF #3139

robloo opened this issue Aug 16, 2020 · 4 comments

Comments

@robloo
Copy link
Contributor

robloo commented Aug 16, 2020

Proposal: Support DependencyPropertyKey and RegisterReadOnly as in WPF

Summary

Support is needed for read-only dependencies properties in UWP/WinUI. This is especially true for collection-type properties backed by a list that shouldn't be changed through the binding system. It will also allow several existing properties to be updated to support binding and MVVM (which is important in several application-specific scenarios).

private static readonly DependencyPropertyKey ReadOnlyPropPropertyKey =
    DependencyProperty.RegisterReadOnly(...);

public static readonly DependencyProperty ReadOnlyPropProperty =
    ReadOnlyPropPropertyKey.DependencyProperty;

public object ReadOnlyProp
{
    get { return GetValue(ReadOnlyPropProperty); }
    protected set { SetValue(ReadOnlyPropPropertyKey, value); }
}

Rationale

This is needed several places (examples listed below) and has been a rather large architectural gap since UWP inception as compared to WPF.

  • <Control>.SelectedItems
  • TwoPaneView.Mode
  • MenuBar.Items

Scope

Capability Priority
Add DependencyPropertyKey Must
Add DependencyProperty.RegisterReadOnly Must

Important Notes

Switching to using read-only DPs in existing controls would be a binary breaking change but as the property accessors could be the same it would be minor. It would just enable binding.

Also see the discussions here:

@chrisglein
Copy link
Member

@MikeHillberg Can you help me understand the tradeoff between RegisterReadOnly versus a OneWay binding? Is the value here that you can't do a TwoWay binding because it's captured by the DependencyProperty itself?

@chrisglein chrisglein removed the needs-triage Issue needs to be triaged by the area owners label Sep 14, 2020
@MikeHillberg
Copy link
Contributor

You can't do a TwoWay binding, nor set it from a Style Setter or VisualState, nor can you call the property setter explicitly from code. Without this feature you can still simply not have a property setter, but that doesn't affect the mechanisms that set the DP directly.

@michael-hawker
Copy link
Collaborator

This is needed for controls and library authors mostly I believe. For instance the WPF docs site an IsMouseOver property or maybe with a StateTrigger you have a IsActive property where you want other UI elements/bindings to observe that state and react to it, but not be able to manipulate it still.

@robloo
Copy link
Contributor Author

robloo commented Jul 19, 2023

Needed

@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Aug 22, 2023
@bpulliam bpulliam removed the needs-triage Issue needs to be triaged by the area owners label Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

7 participants