Xaml 如何根据DataTemplate使用的UserControl内部的VisualState设置图像大小

Xaml 如何根据DataTemplate使用的UserControl内部的VisualState设置图像大小,xaml,windows-store-apps,winrt-xaml,uwp,Xaml,Windows Store Apps,Winrt Xaml,Uwp,我想更改由GridView的DataTemplate使用的UserControl内部图像的大小。到目前为止,我还不能让它工作 我在Macro Minerwa博客中发现了这一点,在DataTemplate中使用自适应触发器的唯一方法是使用UserControl,我用这种方法更改了xaml代码,但仍然没有成功 这是我的GridView: <Grid Grid.Row="1" > <Grid Margin="10"> <Grid

我想更改由GridView的DataTemplate使用的UserControl内部图像的大小。到目前为止,我还不能让它工作

我在Macro Minerwa博客中发现了这一点,在DataTemplate中使用自适应触发器的唯一方法是使用UserControl,我用这种方法更改了xaml代码,但仍然没有成功

这是我的GridView:

<Grid  Grid.Row="1" >

        <Grid Margin="10">
            <GridView ItemsSource="{Binding ListOfApps}" HorizontalAlignment="Center" >
                <GridView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <ItemsWrapGrid x:Uid="WarpGrid" Orientation="Horizontal" MaximumRowsOrColumns="5" />
                    </ItemsPanelTemplate>
                </GridView.ItemsPanel>
                <GridView.ItemTemplate>
                    <DataTemplate>

                        <userControls:AppList/>

                    </DataTemplate>
                </GridView.ItemTemplate>
            </GridView>
        </Grid>
    </Grid>

这是我的用户控件:

<UserControl
x:Class="RemoteController.Views.UserControls.AppList"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:RemoteController.Views.UserControls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
>

<Button x:Name="AppButton" Command="{Binding DataContext.SendPilotCommand, ElementName=AppListPageGrid}" CommandParameter="{Binding Id}" Padding="0" Margin="0" >
    <StackPanel Background="AliceBlue">
        <Image x:Name="AppImage"  Source="{Binding GridImg_url}" Stretch="UniformToFill" />
    </StackPanel>
</Button>


<VisualStateManager.VisualStateGroups>
    <VisualStateGroup x:Name="VisualStateGroup">
        <VisualState x:Name="Small320">
            <VisualState.StateTriggers>
                <AdaptiveTrigger MinWindowWidth="320"/>
            </VisualState.StateTriggers>
            <VisualState.Setters>
                <Setter Target="AppButton.MaxHeight" Value="43"/>
                <Setter Target="AppButton.MaxWidth" Value="72.5"/>
            </VisualState.Setters>
        </VisualState>
        <VisualState x:Name="Large1024">
            <VisualState.StateTriggers>
                <AdaptiveTrigger MinWindowWidth="1024"/>
            </VisualState.StateTriggers>
            <VisualState.Setters>
                <Setter Target="AppButton.MaxHeight" Value="172"/>
                <Setter Target="AppButton.MaxWidth" Value="290"/>
            </VisualState.Setters>
        </VisualState>
    </VisualStateGroup>
</VisualStateManager.VisualStateGroups>


就像我之前写的那样,我想根据屏幕大小设置图像大小。

我会创建一个自定义图像控件来检查窗口大小,并根据大小为通常有效的大小添加前缀。

您可以尝试在名为AppButton的按钮内添加节点吗?@igrali将尝试此操作。@igrali是的,这很有帮助,我把它们移到按钮里面,你能解释一下为什么它不能在用户控制级别上工作吗?嗨,我也遇到了同样的问题,那就是目前VisualState的局限性。