I have a window in which the constructor sets the windows datacontext to an instance of a class called StockViewModel. The window has a syncfusion griddatacontrol with its its ItemsSource="{Binding Path=Stocks}" where Stocks is a property
on StockViewModel. If I create a GridDataVisibleColumn set the MappingName="StockId" a property on the Stock class, and the HeaderText="some string" everything works fine.
However what i need to do is set the HeaderText through binding in the xaml to a property on StockViewModel called StockIdHeader. I have tried a couple things using RelativeSource trying to get to the datacontext of the window but I can't get it to work.
I assume there is a way to do this because you can change the header text with the ShowColumnOptions dialog.
Here's my window, and the datacontext binding code from the windows codebehind.
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:syncfusionGrid="clr-namespace:Syncfusion.Windows.Controls.Grid;assembly=Syncfusion.Grid.Wpf"
Title="Test Syncfusion Grid"
Height="350" Width="525">
Grid.Column="0"
AutoPopulateColumns="False"
AutoPopulateRelations="False"
ShowAddNewRow="False"
ShowColumnOptions="True"
ItemsSource="{Binding Path=Stocks}">
MappingName="StockId"
Width="90"
HeaderText="{Binding StockIdHeader,
RelativeSource={RelativeSource FindAncestor,
AncestorType=Window}}" />
Window Codebehind window constructor:
public MainWindow()
{
InitializeComponent();
StockViewModel _stockViewModel = new StockViewModel();
this.DataContext = _stockViewModel;
}