Hello,
I want to activate/deactivate the possibility to add new row in a ColumnLayout of a XamGrid.
I would like to use the view model (DataContext) and Converter to do it.
What can i do in the following code:
<ig:ColumnLayout Key="Livraisons" CellStyle="{StaticResource GreenRow}" HeaderStyle="{StaticResource ColumnLayoutHeaderGreenStyle}">
<ig:ColumnLayout.AddNewRowSettings> <ig:AddNewRowSettingsOverride AllowAddNewRow="Bottom" /><!--What can i do to use converter to replace "Bottom" value per Converter/none value--> </ig:ColumnLayout.AddNewRowSettings>
<ig:ColumnLayout.FillerColumnSettings> <ig:FillerColumnSettingsOverride HeaderStyle="{StaticResource ColumnLayoutHeaderGreenStyle}" ></ig:FillerColumnSettingsOverride> </ig:ColumnLayout.FillerColumnSettings> <ig:ColumnLayout.Columns> <ig:TextColumn Key="DateLivraison" ></ig:TextColumn> <ig:TextColumn Key="QteLivre"></ig:TextColumn> <ig:TextColumn Key="QteConforme"></ig:TextColumn> </ig:ColumnLayout.Columns> </ig:ColumnLayout>
Second question :
Is it possible to add a button in header to expand all row of columnLayout ?
Thanks
Thank you for the code-snippet you have provided.
1. In order to bind the AllowAddNewRow propety to a boolean property from the ViewModel, you can use a converter inside the binding itself. This way you should be able to respectively pass the necessary data to the AllowAddNewRow (for example: True for Bottom and False for None).
<ig:AddNewRowSettings AllowAddNewRow="{Binding Source={StaticResource viewModel}, Path=IsAddNewRowVisible, Converter={StaticResource addNewConverter}}" /> object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture){ if (((bool)value) == true) return AddNewRowLocation.Bottom; else return AddNewRowLocation.None;}
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture){ if (((bool)value) == true) return AddNewRowLocation.Bottom; else return AddNewRowLocation.None;}
2. In order to add a button to the header area of the XamGrid, an approach I can suggest you is to create a new UnboundField by setting it's HeaderTemplate to a DataTemplate with a Button instance and collapse the cells of the column since no data will be visualized there.
<ig:UnboundColumn Key="#" HeaderTextHorizontalAlignment="Center"> <ig:UnboundColumn.HeaderTemplate> <DataTemplate> <Button MinWidth="50" Margin="5" Click="Button_Click">Toggle Bottom/None</Button> </DataTemplate> </ig:UnboundColumn.HeaderTemplate> <ig:UnboundColumn.CellStyle> <Style TargetType="ig:CellControl"> <Setter Property="Visibility" Value="Collapsed" /> </Style> </ig:UnboundColumn.CellStyle></ig:UnboundColumn>
<ig:UnboundColumn.CellStyle> <Style TargetType="ig:CellControl"> <Setter Property="Visibility" Value="Collapsed" /> </Style> </ig:UnboundColumn.CellStyle></ig:UnboundColumn>
In this case, it is best to access the ViewModel as a pre-defined resource instead of as a DataContext. This is because we will not be able to access the DataContext through the AddNewRowSettings property due to the fact that the AddNewRowSettings is not a visual element.
I have attached a sample that uses the approach from above.
If you have any further questions, please let me know.
Ok it's works but i have last question about this.
In my developpement my DataContext is define as following via DataTemplate file
<DataTemplate DataType="{x:Type ViewModel:ControleEntreCommandeViewModel}"> <View:ControleEntreCommandeView/> </DataTemplate>
If i use windows ressources like the exemple :
<Window.Resources> <local:AddNewConverter x:Key="addNewConverter" /> <vm:ViewModel x:Key="viewModel" /> </Window.Resources>
Done in my xaml:
<Window.Resources><vm:ControleEntreCommandeViewModel x:Key="viewModel" /> </Window.Resources>
The value of "viewModel" is not the DataContext of the current View ? Did i have acces to any value of the current dataContext ?
viewModel
Thank you for the new code-snippet you have provided.
Based on the example in your XAML code:
<Window.Resources> <vm:ControleEntreCommandeViewModel x:Key="viewModel" /></Window.Resources>
The ControleEntreCommandeViewModel instance is not the DataContext of the Window (your current View). It is merely a resource of the Window, that should be explicitly referenced in order to get the respective data from it, just like the example from above:
<ig:AddNewRowSettings AllowAddNewRow="{Binding Source={StaticResource viewModel}, Path=IsAddNewRowVisible, Converter={StaticResource addNewConverter}}" />
If you have any further questions, please let me know