0
votes

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 :)

1
Can you please post xaml code? - Archana
@Archana Sorry for a late reply, but yes, ff course... This is the GridView with simplified xaml: <GridView x:Name="DATAGRID" ItemsSource="{Binding Data}" SelectionMode="Single"> <GridView.ItemTemplate> <DataTemplate> <cc:MyControl x:Name="AA" Style="{StaticResource MyControlStyle1}"> </DataTemplate> </GridView.ItemTemplate> </GridView> - evil gugl
sorry, I just can't propery format the 'code' block :( - evil gugl
@evilgugl I realize I'm late to the game, but you can insert code in comments by surrounding the code with the backtick ` (so like `my code here`) but, more importantly, you can edit your original question and properly format the code there. It's fair game to insert more code in your original question to address comments or even answers. - ruffin

1 Answers

1
votes

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