SideEffects
Topic Author
Posts: 2
Joined: 19 Feb 2020, 13:38

DependencyObject as Binding Proxy not working since update from 2.2.3 to 3.1.2

30 Dec 2021, 13:11

To avoid spamming XAML files with confusing AnchestorType bindings, we were using DepencendyObjects as Binding Proxies as described in this Blog:

https://code.4noobz.net/wpf-mvvm-proxy-binding/

Our implementation:
public class BindingProxy : Freezable
    {
#if !NOESIS
        protected override Freezable CreateInstanceCore()
        {
            return new BindingProxy();
        }
#endif

        public object Data
        {
            get { return (object)GetValue(DataProperty); }
            set { SetValue(DataProperty, value);  }
        }

        public static readonly DependencyProperty DataProperty =
            DependencyProperty.Register(nameof(Data), typeof(object), typeof(BindingProxy), new UIPropertyMetadata(null));
    }
The proxies are defined inside XAML like this:
  <Grid Margin="10" >
    <Grid.Resources>
      <sfx:BindingProxy x:Key="Binding.Root" Data="{Binding}"/>
    </Grid.Resources>
    <Grid.RowDefinitions>
      <RowDefinition Height="40"/>
      <RowDefinition Height="25"/>
      <RowDefinition/>
    </Grid.RowDefinitions>
    ...
Trying to bind the proxy (inside an item template) always results in a null value:
            <Button x:Name="Expander" Grid.Column="0"
                          sfx:ExpanderHelper.Expanded="{Binding IsExpanded, Mode=OneWay}"
                          Command="{Binding Data.ToggleExpansionCommand, Source={StaticResource Binding.Root}}"
                          CommandParameter="{Binding}" Margin="-4"
                          Visibility="{Binding IsExpandable, Mode=OneWay, Converter={StaticResource BoolToVisibility}}">
            ...
This worked like a charm as long as we used Noesis 2.2.3. However, since we updated to 3.1.2, these bindings don't seem to work anymore.
I'm not sure what all has changed ever since. It looks like, the DependencyObject of the Binding Proxy never gets created. Are we missing something?
 
User avatar
sfernandez
Site Admin
Posts: 2569
Joined: 22 Dec 2011, 19:20

Re: DependencyObject as Binding Proxy not working since update from 2.2.3 to 3.1.2

30 Dec 2021, 13:30

I think this could be related to this other post: viewtopic.php?f=3&t=2500
If you wrap your proxy definition in a ResourceDictionary node does it work?
<Grid.Resources>
  <ResourceDictionary>
      <sfx:BindingProxy x:Key="Binding.Root" Data="{Binding}"/>
  </ResourceDictionary>
</Grid.Resources>
 
SideEffects
Topic Author
Posts: 2
Joined: 19 Feb 2020, 13:38

Re: DependencyObject as Binding Proxy not working since update from 2.2.3 to 3.1.2

30 Dec 2021, 13:39

Wrapping it inside a <ResourceDictionary> did the trick! Now the bindings are working again.
Thank you for the prompt reply!
 
User avatar
sfernandez
Site Admin
Posts: 2569
Joined: 22 Dec 2011, 19:20

Re: DependencyObject as Binding Proxy not working since update from 2.2.3 to 3.1.2

10 Jan 2022, 18:27

Added ticket #2234 to solve this issue.
 
aberro
Posts: 6
Joined: 03 Feb 2018, 20:33

Re: DependencyObject as Binding Proxy not working since update from 2.2.3 to 3.1.2

28 Jan 2022, 15:46

I think this could be related to this other post: viewtopic.php?f=3&t=2500
If you wrap your proxy definition in a ResourceDictionary node does it work?
<Grid.Resources>
  <ResourceDictionary>
      <sfx:BindingProxy x:Key="Binding.Root" Data="{Binding}"/>
  </ResourceDictionary>
</Grid.Resources>
Could this be a same bug? If so, how can I fix it?
 
User avatar
sfernandez
Site Admin
Posts: 2569
Joined: 22 Dec 2011, 19:20

Re: DependencyObject as Binding Proxy not working since update from 2.2.3 to 3.1.2

28 Jan 2022, 18:21

Could this be a same bug? If so, how can I fix it?
No, as mentioned in that post it is a problem of how we expose that multiple inheritance to Noesis.

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Semrush [Bot] and 2 guests