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,
I am just checking the progress of this issue and was wondering if you managed to achieve your goal or if you need any further assistance on the matter.
How can the Cell in the Edit Mode take the Width and Height of a User Control ?
Basically, in edit mode I want to open my userControl as a dropdown(basically having style of dropdown), so that the cell does not looks ugly.
I can suggest you use Adorning Editor. You can see how to do this in the Samples Browser under xamDataGrid / Editing & Selection / Adorning Editors section, where there is a sample showing this.
Hope this helps you.