Last active
June 5, 2016 21:34
-
-
Save heiswayi/b9ebb391e1e37ad41229bd2f88ddb60b to your computer and use it in GitHub Desktop.
To bind to data when the DataContext is not inherited
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BindingProxy : Freezable | |
{ | |
#region Overrides of Freezable | |
protected override Freezable CreateInstanceCore() | |
{ | |
return new BindingProxy(); | |
} | |
#endregion | |
public object Data | |
{ | |
get { return (object)GetValue(DataProperty); } | |
set { SetValue(DataProperty, value); } | |
} | |
// Using a DependencyProperty as the backing store for Data. This enables animation, styling, binding, etc... | |
public static readonly DependencyProperty DataProperty = | |
DependencyProperty.Register("Data", typeof(object), typeof(BindingProxy), new UIPropertyMetadata(null)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<DataGrid.Resources> | |
<local:BindingProxy x:Key="proxy" Data="{Binding}" /> | |
</DataGrid.Resources> | |
<DataGridTextColumn Header="Price" Binding="{Binding Price}" IsReadOnly="False" | |
Visibility="{Binding Data.ShowPrice, | |
Converter={StaticResource visibilityConverter}, | |
Source={StaticResource proxy}}"/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment