Hi,
I have the following XamDataGrid.For the field defined, I need to show string while in non-edit mode and an user control(views:ProductView) in edit mode. It does exactly what I need, except it doesnot fire any properties inside the ProductViewModel in the edit mode. Looks like it is not binding to the SelectedProductViewModel. I have a doubt I am not using the styles properly. Can you please point out where I am going wrong ?
<igdp:XamDataGrid Grid.Row="1" DataSource="{Binding Path=ListOfProduct}">
<igdp:XamDataGrid.Resources> <Style x:Key="ProductCellEditStyle" TargetType="{x:Type igEditors:XamTextEditor}"> <Setter Property="Template" > <Setter.Value> <ControlTemplate> <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <TextBox Text="{Binding Description}" /> </Grid> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="EditTemplate" > <Setter.Value> <ControlTemplate TargetType="{x:Type igEditors:XamTextEditor}"> <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <views:ProductView DataContext="{Binding SelectedProductViewModel, UpdateSourceTrigger=PropertyChanged}"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </igdp:XamDataGrid.Resources>
<igdp:XamDataGrid.FieldLayouts> <igdp:FieldLayout> <igdp:UnboundField BindingPath="Description" Label="Product" Name="Product"> <igdp:Field.Settings> <igdp:FieldSettings EditorStyle="{StaticResource ProductCellEditStyle}" > <igdp:FieldSettings.CellValuePresenterStyle> <Style TargetType="{x:Type igdp:CellValuePresenter}" BasedOn="{StaticResource FontSizeStyle}"/> </igdp:FieldSettings.CellValuePresenterStyle> </igdp:FieldSettings> </igdp:Field.Settings> </igdp:UnboundField> </igdp:XamDataGrid.FieldLayouts>
</igdp:XamDataGrid>
Inside my Main VM or the dataContext for xamDatagrid=========================================================public class MainViewModel : ViewModelBase{
private IEnumerable<Product> _listOfProduct; public IEnumerable<Product> ListOfProduct { get { return _listOfProduct ?? (_listOfProduct = GetProd();) } set { _listOfProduct = value; NotifyPropertyChanged("ListOfProduct"); } } private ProductViewModel _SelectedProductViewModel; public ProductViewModel SelectedProductViewModel { get { return _SelectedProductViewModel; } set { _SelectedProductViewModel = value; NotifyPropertyChanged("SelectedProductViewModel"); } }
//using interaction public void XamProductMatchGridEditModeStarting(object sender, EditModeStartingEventArgs e) { SelectedProductViewModel = somelogictogetit(); }}
Inside my secondary VM or the dataContext for UserControl(views:ProductView)============================================================================public class ProductViewModel : ViewModelBase{ private string _statusMessage; public string StatusMessage { get { return _statusMessage; } protected set { _statusMessage = value; RaisePropertyChanged(() => StatusMessage); } }}
Hello Rajib,
Thank you for your post. I have been looking into it, but without a sample project where this is reproduced I am not able to conclude what can cause this behavior, so could you please send us such sample. Also could you please give as more details about the result you want to achieve?
Looking forward for your reply.