Carl Rynegardh
Carl Rynegardh

Reputation: 558

Binding to column(cell) value

I am trying to customize a column inside a DevExpress GridControl. I basically want two rows in each cell in the column. One with some random text and another one containing the property Max defined in my ObservableCollection Stocks, which is set as the ItemsSource. Without using the GridColumn.CellTemplate the cell receives has the correct Max property value. But when the Grid.CellTemplate is introduced I am unnable to have the Max property value printed out. I'm assuming the Binding is incorrect but cannot figure out what is wrong.

     <dxg:GridControl  EnableSmartColumnsGeneration="True" ItemsSource="{Binding Stocks}" 
                     SelectionMode="None" AllowLiveDataShaping="True"     >

           <dxg:GridControl.Columns>
             <dxg:GridColumn x:Name="MaxColumn" Binding="{Binding Max, Mode=TwoWay}" MinWidth="60" Width="60" AllowResizing="True" 
                FixedWidth="true" Header="Max" ReadOnly="True">
                <dxg:GridColumn.CellTemplate>
                    <DataTemplate >
                        <Grid >
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <TextBlock Text="Max is..." ></TextBlock>
                            <TextBlock Grid.Row="1"  Text="{Binding Max, Mode=TwoWay}"></TextBlock>
                        </Grid>
                    </DataTemplate>
                 </dxg:GridColumn.CellTemplate>
              </dxg:GridColumn>
           </dxg:GridControl.Columns>

    </dxg:GridControl>

The first picture is without the CellTemplate, the second one is with the CellTemplate.

Without the CellTemplate

With the CellTemplate

Appreciate all help :)

Upvotes: 0

Views: 1726

Answers (1)

ViVi
ViVi

Reputation: 4464

The cause of this issue is the incorrect Binding Path. Please note that the CellTemplate content uses the GridCellData object as DataContext. The Binding Path should look different based on what ViewModel contains the required command:

The source is a row's ViewModel: XAML:

Command="{Binding RowData.Row.Max}"

The source is bound to the DXGrid control as DataContext: XAML:

Command="{Binding View.DataContext.Max}"

Upvotes: 2

Related Questions