Cannot set LayoutManager in Style

Hi,

I'm trying to set the LayoutManager depending of the user settings (switch between LinearLayout and GridLayout.


<Style TargetType="listView:SfListView">

                                                            <!-- Default for CardView -->

                                                            <Setter Property="ItemTemplate" Value="{StaticResource CardTemplate}"/>

                                                            <Setter Property="LayoutManager">

                                                                <Setter.Value>

                                                                    <!-- Printers per row -->

                                                                    <listView:GridLayout

                                                                        SpanCount="{OnIdiom Tablet=3, Default=1}"

                                                                        />

                                                                </Setter.Value>

                                                            </Setter>


                                                            <Style.Triggers>

                                                                <DataTrigger

                                                                    TargetType="listView:SfListView"

                                                                    Binding="{Binding UseCardViewForFiles}"

                                                                    Value="False"

                                                                    >

                                                                    <Setter Property="ItemTemplate" Value="{StaticResource FileTemplate}"/>

                                                                    <Setter Property="LayoutManager">

                                                                        <Setter.Value>

                                                                            <!-- One printer per row -->

                                                                            <listView:LinearLayout />

                                                                        </Setter.Value>

                                                                    </Setter>

                                                                </DataTrigger>

                                                            </Style.Triggers>

                                                        </Style>

However, this GridLayout will not be set.



2 Replies

LN Lakshmi Natarajan Syncfusion Team July 26, 2021 12:25 PM UTC

Hi Andreas, 
 
Thank you for using Syncfusion products. 
 
We have checked the reported query “Cannot set LayoutManager in Style” from our side. We could reproduce the reported scenario at our side. Currently, we are analyzing the same scenario in both sample and source level. We will check completely and update you further details on July 28, 2021. We appreciate your patience until then. 
 
Lakshmi Natarajan 
  
 



LN Lakshmi Natarajan Syncfusion Team July 28, 2021 12:24 PM UTC

Hi Andreas, 
 
Thank you for your patience. 
 
We have checked the reported query “Cannot set LayoutManager in Style” in both source and framework level from our side. We would like to inform you that the base type of the LayoutManager is BindableObject and setting BindableObject instance through setter is not working in Xamarin.Forms. Also, we could reproduce the reported scenario in framework level itself.  
 
Meanwhile, you can overcome the reported scenario by using Triggers. Please refer to the following code snippets for more reference, 
 
<Style TargetType="listView:SfListView"> 
    <Style.Triggers> 
        <DataTrigger TargetType="listView:SfListView"  
                    Binding="{Binding UseCardViewForFiles}" 
                    Value="False" > 
 
            <Setter Property="ItemTemplate" Value="{StaticResource FileTemplate}"/> 
            <Setter Property="LayoutManager"> 
                <Setter.Value> 
                    <listView:LinearLayout /> 
                </Setter.Value> 
            </Setter> 
        </DataTrigger> 
 
        <DataTrigger TargetType="listView:SfListView"  
                    Binding="{Binding UseCardViewForFiles}" 
                    Value="True" > 
 
            <Setter Property="ItemTemplate" Value="{StaticResource CardTemplate}"/> 
            <Setter Property="LayoutManager"> 
                <listView:GridLayout SpanCount="{OnIdiom Tablet=3, Phone=2, Default=2}" /> 
            </Setter> 
        </DataTrigger> 
    </Style.Triggers> 
</Style> 
 
Please let us know if you need further assistance. 
 
Lakshmi Natarajan 
 


Loader.
Up arrow icon