Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Device orientation (Portrait, Landscape) based styling not working on GridView

$
0
0

Hi.

I have a <style> element and I want that if the device in Portrait or in Landscape the Margin of the Grid has different values.

But it seems it does not work, because the margin is always 0.

<ContentView.Resources>
        <ResourceDictionary>
            <Style x:Key="CategoryGridStyle"  x:Name="CategoryGridStyle" TargetType="Grid">
                <Setter Property="ColumnSpacing" Value="10" />
                <Setter Property="RowSpacing" Value="10" />
                <Setter Property="HorizontalOptions" Value="FillAndExpand" />
                <Setter Property="VerticalOptions" Value="FillAndExpand" />
                <!--<Setter Property="Margin" Value="30, 100"/>-->
                <Setter Property="VisualStateManager.VisualStateGroups">
                    <VisualStateGroupList>
                        <VisualStateGroup x:Name="OrientationStates">
                            <VisualState Name="Portrait">
                                <VisualState.Setters>
                                    <Setter Property="Margin" Value="30, 100" />
                                </VisualState.Setters>
                            </VisualState>

                            <VisualState Name="Landscape">
                                <VisualState.Setters>
                                    <Setter Property="Margin" Value="30, 100" />
                                </VisualState.Setters>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateGroupList>
                </Setter>

However if I uncomment this line:
<!--<Setter Property="Margin" Value="30, 100"/>--> The margin will works. But I need different margin values on different device orientation :)

Bonus question: is it possible to do with OnIdiom element too? (Detect if it is phone or tablet)


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>