microsoft / microsoft-ui-xaml

WinUI: a modern UI framework with a rich set of controls and styles to build dynamic and high-performing Windows applications.
MIT License
6.38k stars 683 forks source link

PropertyPath can't be constructed with custom Attached Property #5438

Open hawkerm opened 3 years ago

hawkerm commented 3 years ago

Describe the bug

Older issue, see threads like Stack Overflow and here

The PropertyPath class can't take a string that represents a custom attached property. It'd be nice if it could take a fully qualified path like (Microsoft.Toolkit.Uwp.UI.Controls.UniformGrid.AutoLayout) since xmlns isn't a thing in the code-behind, which is the problem. Otherwise, it'd also be nice if you could just pass the specific DependencyProperty value in as an argument like UniformGrid.AutoLayoutProperty.

Steps to reproduce the bug

  1. Create a new project with a custom attached property.
  2. Try and construct a PropertyPath with a string for that attached property...
System.ArgumentException
  HResult=0x80070057
  Message=Value does not fall within the expected range.
  Source=Windows
  StackTrace:
   at Windows.UI.Xaml.Data.Binding.put_Path(PropertyPath value)
   at Microsoft.Toolkit.Uwp.UI.Controls.Future.UniformGridView.SetupChildBinding(ContentPresenter cp) in Controls\UniformGridView.cs:line 96
   at Microsoft.Toolkit.Uwp.UI.Controls.Future.UniformGridView.ContentPresenter_Loaded(Object sender, RoutedEventArgs args) in Controls\UniformGridView.cs:line 77

Expected behavior Able to bind to a custom attached property in a PropertyPath from code-behind.

Version Info

NuGet package version: WUX 19041 SDK

Windows 10 version Saw the problem?
Insider Build (xxxxx)
October 2020 Update (19042) Yes
May 2020 Update (19041)
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Xbox
Surface Hub
IoT
StephenLPeters commented 3 years ago

@RealTommyKlein Is this you guys or framework?

RealTommyKlein commented 3 years ago

@StephenLPeters - I'd say framework. This is a scenario gap in the framework's Binding object when it's used in code-behind, as opposed to x:Bind or markup features.

chrisglein commented 3 years ago

From initial look at this it's something hasn't worked on UWP XAML but did in WPF. Sounds like a gap in doing code-centric bindings with PropertyPaths to attached properties that's just never been filled in. I imagine the workaround is to structure the binding relationship with more code and less indirection through paths. Less sharing with markup that way though, of course.

hawkerm commented 3 years ago

Yeah, in code-behind we already have a typed construct for a definition of each Dependency Property already. So it'd be nice if PropertyPath just had an overload which took a reference to the DependencyProperty like Grid.RowProperty or whichever one we wanted to bind to. Then it'd be more strongly-typed, easy to discover and create paths, and work for both regular DP and attached properties as they use the same setup.