Can you databind headertext?
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;
}
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: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">
AutoPopulateColumns="False"
AutoPopulateRelations="False"
ShowAddNewRow="False"
ShowColumnOptions="True"
ItemsSource="{Binding Path=Stocks}">
Width="90"
HeaderText="{Binding StockIdHeader,
RelativeSource={RelativeSource FindAncestor,
AncestorType=Window}}" />
Window Codebehind window constructor:
public MainWindow()
{
InitializeComponent();
StockViewModel _stockViewModel = new StockViewModel();
this.DataContext = _stockViewModel;
}
SIGN IN To post a reply.
3 Replies
GK
Ganesan K
Syncfusion Team
November 30, 2009 06:53 AM UTC
Hi Troy,
Thanks for using Syncfusion products.
Right now it is not possible to databind a HeaderText property, since the GridDataVisibleColumn is just a DependencyObject, for DataBinding it requires to be a FrameworkElement.
Please let us know if you need any more details.
Thanks
Ganesan
Thanks for using Syncfusion products.
Right now it is not possible to databind a HeaderText property, since the GridDataVisibleColumn is just a DependencyObject, for DataBinding it requires to be a FrameworkElement.
Please let us know if you need any more details.
Thanks
Ganesan
FM
Francois Mongeau
June 22, 2015 10:08 PM UTC
Is it possible now, or will it Ever be?
JS
Jayapradha S
Syncfusion Team
June 23, 2015 12:19 PM UTC
Hi Troy Johnson,
Thank you for contacting Syncfusion support.
We analyzed your requirement and you can set the header text through binding from viewmodel as shown in the below code snippet:
Code Snippet:
Please let us know if you require any further assistance on this.
Regards,
Jayapradha
Thank you for contacting Syncfusion support.
We analyzed your requirement and you can set the header text through binding from viewmodel as shown in the below code snippet:
Code Snippet:
|
C#: private string headerText = "Column1";
public string HeaderColumn { get { return headerText; } set { headerText = value; } <Window.Resources> <local:ViewModel x:Key="viewModel"/> <syncfusion:GridDataVisibleColumn MappingName="OrderID" |
Please let us know if you require any further assistance on this.
Regards,
Jayapradha
SIGN IN To post a reply.
- 3 Replies
- 4 Participants
-
TJ Troy Johnson
- Nov 27, 2009 01:39 AM UTC
- Jun 23, 2015 12:19 PM UTC