Open dragomirtitian opened 3 years ago
You create your SomeProp
with public static readonly DependencyProperty
which means you can use it as a global attached properties for each button. You define two attachecd DependencyProperty with the same name, which can cause confusion when used. You can name the DependencyProperty as SomeProp2
for your project, then you don't need to change the local alias of the namespace to cx
.
@daisyTian0517 The real world issue is a bit more complex. I agree under normal circumstances, you can rename the class or the property but in my specific use case this is not practical. The issue occurs for me when a container application loads two plugins, that use two different version of a shared library. The dependency property in conflict comes from the different versions of the same library, so renaming the property each time you create a new version is not really practical. (The workaround we are working on is renaming the local alias as a pre build step when creating the release build, but this isn't exactly great either)
I think I might have a very similar issue where binding uses attached property instead of the main property with the same name. E.g. I have a MyControl
with its own DependencyProperty
Prop
of type IEnumerable
, and also an attached property with the same name Prop
defined in a custom class Behavior
.
Given this setup, on loading XAML I randomly get the binding to be attached to either MyControl.Prop
or Behavior.Prop
:
<Grid>
<Grid.Resources>
<ResourceDictionary>
<CollectionContainer x:Key="MyCollection" Collection="{Binding Prop, Source={x:Reference MyControl1}}"/>
</ResourceDictionary>
</Grid.Resources>
<my:MyControl x:Name="MyControl1">
<my:Behavior.Prop>
<sys:Double>40</sys:Double>
</my:Behavior.Prop>
</my:MyControl>
</Grid>
From my understanding, MyCollection
should never bind to the attached property because I did not specify the full path to it in Binding
(e.g. it would have to be {Binding (my:Behavior.Prop), ...}
to use attached property). It should always bind to MyControl.Prop
.
Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
Problem description: Given two attached properties with the same name in a class with the same name but in different namespaces and aliased with the same xmlns prefix in a xaml file, the
PropertyPathWorker
will end up using only the first encountered property. This is becauseAccessorTable
uses the local name as the cache key even though the two properties with the same local name may be unrelated.Actual behavior: In the second xaml file, the binding actually refers to the first attached property, while the property on the button refers to the correct attached property
Expected behavior: The correct property is used in each xaml file both on the target control and in the binding
Minimal repro:
MainWindow.xaml
UserControl1.xaml
UserControl1.xaml.cs
UserControl1.xaml
UserControl2.xaml.cs
The code above will display two controls, both with one static text, and one through a binding on an attached property. Usercontrol1 should display 1 1, while should display Usercontrol1 should display 2 2. In actuality Usercontrol2 displays 2 -1. This is because teh binding in Usercontrol2 will use the attached property in
UserControl1Props
which has a default of-1
If you change the local alias of the namespace from
c
tocx
in any of the user controls the code works as expected: