Skip to content

Instantly share code, notes, and snippets.

@chrisg32
Created August 1, 2019 19:34
Show Gist options
  • Save chrisg32/1e4a19310b60a7e9dc1e2fa601921ef9 to your computer and use it in GitHub Desktop.
Save chrisg32/1e4a19310b60a7e9dc1e2fa601921ef9 to your computer and use it in GitHub Desktop.
using System;
using System.Windows;
namespace Ldar.Chateau.Prism.Resources
{
/// <summary>
/// Some markup elements (DataGridTemplateColumn and telerik:GridViewDataColumn.Header, for example)
/// are not part of the visual or logical tree, and therefore has no binding ancestor (or any
/// ancestor) so the RelativeSource doesn't work. When you need RelativeSource for binding,
/// we instead have to bind to a local proxy.
/// http://stackoverflow.com/questions/15494226/cannot-find-source-for-binding-with-reference-relativesource-findancestor
/// </summary>
public class BindingProxy : Freezable
{
protected override Freezable CreateInstanceCore()
{
return new BindingProxy();
}
public object Data
{
get { return (object)GetValue(DataProperty); }
set { SetValue(DataProperty, value); }
}
public static readonly DependencyProperty DataProperty =
DependencyProperty.Register("Data", typeof(object), typeof(BindingProxy), new UIPropertyMetadata(null));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment