Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
350
Xamgrid activate adding newRowSettings
posted

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

Parents
  • 6365
    Offline posted

    Hello,

    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;
    }


    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>


    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.

    XamGrid_sample.zip
Reply Children