We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Can you databind headertext?

Thread ID:

Created:

Updated:

Platform:

Replies:

91666 Nov 27,2009 01:39 AM UTC Jun 23,2015 12:19 PM UTC WPF 3
loading
Tags: GridDataControl
Troy Johnson
Asked On November 27, 2009 01:39 AM UTC

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;
}

Ganesan K [Syncfusion]
Replied On 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

Francois Mongeau
Replied On June 22, 2015 10:08 PM UTC

Is it possible now, or will it Ever be?

Jayapradha S [Syncfusion]
Replied On 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:

C#: 

private string headerText = "Column1";


        public string HeaderColumn

        {

            get { return headerText; }

            set { headerText = value; }
        }

XAML:

<Window.Resources>

        <local:ViewModel x:Key="viewModel"/>
</Window.Resources>

  <syncfusion:GridDataVisibleColumn MappingName="OrderID"
                                    HeaderText="{Binding HeaderColumn, Source={StaticResource viewModel}}"/>



Please let us know if you require any further assistance on this.

Regards,
Jayapradha

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;