简体   繁体   中英

UWP - VisualStateManager - GridView ItemStyle

once again, I may be over-complicating simple things...

I'm trying to apply different styles to my custom control that is set as a GridView ItemTemplate (depending on the app window width).

I tried to just use VisualStateManager and set style property to the custom control, but It won't work, since the controls are dynamically generated.

Latest thing I've tried is to change whole DataTemplate instead of just Style...

Unfortunately It also doesn't work and I get following exception:

System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.

at Windows.UI.Xaml.FrameworkElement.MeasureOverride(Size availableSize)


XAML code:

<GridView x:Name="DATAGRID" ItemsSource="{Binding Data}" SelectionMode="Single">
    <GridView.ItemTemplate>
        <DataTemplate>
            <cc:MyControl x:Name="AA" Style="{StaticResource MyControlStyle1}">
        </DataTemplate>
    </GridView.ItemTemplate>
</GridView>

Anyone has any idea what does it mean and how to solve it?

Thank you :)

In the ItemTemplate you can use visual states with adaptive triggers to change properties of UI elements based on screen width. https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.adaptivetrigger.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM