This is a migrated thread and some comments may be shown as answers.

DatamemberBinding and Header

4 Answers 763 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 04 Aug 2011, 12:33 PM
Hello,

I am using the MVVM pattern.  I have a GridView on a usercontrol that has the datacontext set to a viewmodel.  The viewmodel contains an ObservableCollection of model objects that are bound to the ItemsSource of the GridView.  My GridViewDataColumn.Header properties are bound to some properties in the viewmodel and everything works as expected.  The Header values are genrated dynamically and dispalyed properly through the binding.  When I add a DataMemberBinding to a GridViewDataColumn and bind it to a property from the object collection, I get unexpected Header value.  The Header will display the value "SourceName".  This only happens when the SourceName property exists on the model object and a successful binding is created for the DataMemberBinding property.  If I put in a value such as SourceNameTest, the Header is displayed correctly.  Here is a snippet of one of the columns in question.  As you can see it is a very simple column definition.  Could you please help me understand if there is way to accomplish what I am trying to do.

<telerik:GridViewDataColumn DataMemberBinding="{Binding SourceName}" Header="{Binding SourceObjectHeader}" >
Thanks,

Jason

 

 

 

 

4 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 04 Aug 2011, 03:18 PM
Hi Jason,

 
You may take a look at the following forum thread "Binding Header Text" for further info. 


Kind regards,
Vanya Pavlova
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Jason
Top achievements
Rank 1
answered on 09 Aug 2011, 07:11 PM
Hello,

I was unable to find a solution to my problem through the link that you provided.  My header text binds great when I do this.
 

 

 

 

 

<telerik:GridViewDataColumn >

 

 

 

 

    <telerik:GridViewDataColumn.Header>

 

 

 

 

        <TextBlock Text="{Binding SourceAttributeHeader}" Margin="0,0,5,0" />

 

 

 

 

    </telerik:GridViewDataColumn.Header>

 

 

 

 

    <telerik:GridViewDataColumn.CellTemplate>

 

 

 

 

        <DataTemplate>

 

 

 

 

            <telerik:RadComboBox ItemsSource="{Binding SourceAttributeNames}" IsMouseWheelEnabled="False"

 

 

 

 

                SelectedIndex="{Binding SelectedSourceAttributeIndex,Mode=TwoWay,ValidatesOnDataErrors=True,NotifyOnValidationError=True}">

 

 

 

 

            </telerik:RadComboBox>

 

 

 

 

        </DataTemplate>

 

 

 

 

    </telerik:GridViewDataColumn.CellTemplate>

 

 

 

 

</telerik:GridViewDataColumn>

 

As soon as I add the DataMemberBinding to the GridViewDataColumn, I get a blank in the header text at runtime.  The code looks like this.

 

 

 

 

 

 

<telerik:GridViewDataColumn DataMemberBinding="{Binding SelectedSourceAttributeName}">

 

 

 

 

    <telerik:GridViewDataColumn.Header>

 

 

 

 

        <TextBlock Text="{Binding SourceAttributeHeader}" Margin="0,0,5,0" />

 

 

 

 

    </telerik:GridViewDataColumn.Header>

 

 

 

 

    <telerik:GridViewDataColumn.CellTemplate>

 

 

 

 

        <DataTemplate>

 

 

 

 

 

 

 

 

 

            <telerik:RadComboBox ItemsSource="{Binding SourceAttributeNames}" IsMouseWheelEnabled="False"

 

 

 

 

                SelectedIndex="{Binding SelectedSourceAttributeIndex,Mode=TwoWay,ValidatesOnDataErrors=True,NotifyOnValidationError=True}">

 

 

 

 

            </telerik:RadComboBox>

 

 

 

 

        </DataTemplate>

 

 

 

 

    </telerik:GridViewDataColumn.CellTemplate>

 

 

 

 

</telerik:GridViewDataColumn>

 

Please try to help.

Jason

 

 

 

0
Vanya Pavlova
Telerik team
answered on 09 Aug 2011, 07:53 PM
Hello Jason,

 

As it was proposed in the previously referenced thread you should set the DataContext of the Header to be the DataContext of RadGridView and afterwards to bind its Header property as shown below:


<telerik:GridViewDataColumn.Header>
                       <TextBlock Text="{Binding SourceAttributeHeader}" DataContext="{StaticResource MyViewModel}" />
</telerik:GridViewDataColumn.Header>


May you verify how this solution does not work in your case?


Kind regards,
Vanya Pavlova
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Jason
Top achievements
Rank 1
answered on 10 Aug 2011, 12:38 PM
Hi Vanya,

I am unable to use my viewmodel in the xaml since it does not have a parameterless constructor.  We are using prism with dependency injection.  If you have another suggestion that would be appreciated.

Thanks,

Jason
Tags
GridView
Asked by
Jason
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Jason
Top achievements
Rank 1
Share this question
or