GridColumn Custom Cell HorizontalAlignment

Posted by: jared.fritsch on 24 October 2017, 7:49 am EST

    • Post Options:
    • Link

    Posted 24 October 2017, 7:49 am EST

    I have a custom cell that I am trying to center align within a column. I have set the HorizontalAlignment property to Center, but nothing seems to be happening.

    This seems to work just fine:

    
    <c1:GridColumn
        HorizontalAlignment="Center"
        Binding="MyColumn1" />
    
    

    However, this does not:

    
    <c1:GridColumn
        HorizontalAlignment="Center">
        <c1:GridColumn.CellTemplate>
            <DataTemplate>
                <Label
                    Text="Test" />
            </DataTemplate>
        </c1:GridColumn.CellTemplate>
    </c1:GridColumn>
    
    

    Setting HorizontalOptions on the Label doesn’t work either:

    
    <c1:GridColumn
        HorizontalAlignment="Center">
        <c1:GridColumn.CellTemplate>
            <DataTemplate>
                <Label
                    HorizontalOptions="Center"
                    Text="Test" />
            </DataTemplate>
        </c1:GridColumn.CellTemplate>
    </c1:GridColumn>
    
    

    This appears to be a problem on UWP, but not Android. Not sure about iOS at this time. I am using FlexGrid version 2.4.20172.195 which as of the writing of this post is still pre-release.

  • Posted 25 October 2017, 4:40 am EST

    Hi Jared

    Try something like this instead:

                
    <c1:GridColumn Header="Test Column" Width="*">
                    <c1:GridColumn.CellTemplate>
                        <DataTemplate>
                            <Grid>
                                <Label Text="Test" HorizontalOptions="Center"/>
                            </Grid>
                        </DataTemplate>
                    </c1:GridColumn.CellTemplate>
                </c1:GridColumn>
    
    

    It should work universally across platforms. I’ll mention something to the developers about this. I’m not sure if HorizontalAlignment is necessarily honored in the case of custom cells, but I’ll inquire further about it.

    Kelley

  • Posted 25 October 2017, 5:32 am EST

    Looks like wrapping the control in a container control is a good workaround for now. I was able to wrap it in a ContentView with success as well.

    Thanks, Kelley!

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels