我正在使用Windows 10的计划应用程序并使用GridView显示课程卡。它们应该在窗口宽时具有固定的宽度,并且当它很窄时使用完整的GridView宽度(实际上,它应该看起来像ListView)。
我使用VisualStateManager在Wide状态下设置固定的GridViewItem宽度,但我无法理解如何使其伸展。
以下是我的风格:
test <- data.frame(V3=factor("Yes", levels=levels(all_data$V3)))
test
V3
1 Yes
levels(test$V3)
[1] "No" "Yes"
data.matrix(test)
V3
[1,] 2
视觉状态:
<Style x:Key="GridViewItemStyle" TargetType="GridViewItem">
<Setter Property="Margin" Value="10, 10, 10, 10" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
</Style>
<Style x:Key="NarrowGridViewItemStyle" BasedOn="{StaticResource ResourceKey=GridViewItemStyle}" TargetType="GridViewItem">
<Setter Property="Width" Value="{Binding ActualWidth, ElementName=TimetableGrid}" />
</Style>
<Style x:Key="WideGridViewItemStyle" BasedOn="{StaticResource ResourceKey=GridViewItemStyle}" TargetType="GridViewItem">
<Setter Property="Width" Value="450"/>
</Style>
GridView本身:
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="AdaptiveStates" CurrentStateChanged="AdaptiveStates_OnCurrentStateChanged">
<VisualState x:Name="NarrowState">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="0" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="TimetableGrid.ItemContainerStyle" Value="{StaticResource ResourceKey=NarrowGridViewItemStyle}" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="WideState">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="600"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="NavigationSplitView.DisplayMode" Value="CompactOverlay"/>
<Setter Target="HamburgerButton.Background" Value="#3F51B5"/>
<Setter Target="HamburgerButton.Foreground" Value="White"/>
<Setter Target="HeaderBorder.Margin" Value="20,0,0,0"/>
<Setter Target="TimetableGrid.ItemContainerStyle" Value="{StaticResource ResourceKey=WideGridViewItemStyle}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
实际结果:
我是UWP开发和XAML的新手,并感谢任何帮助。感谢。
答案 0 :(得分:1)
您需要为要拉伸的项目替换ItemsPanelTemplate
。
尝试在Page.Resources
中定义新资源:
<ItemsPanelTemplate x:Key="NarrowItemsPanelTemplate">
<ItemsStackPanel />
</ItemsPanelTemplate>
然后修改您的VisualStateManager
以另外设置ItemsPanel
的{{1}}属性:
NarrowState
无需以任何方式修改<VisualState x:Name="NarrowState">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="0" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="TimetableGrid.ItemContainerStyle"
Value="{StaticResource ResourceKey=NarrowGridViewItemStyle}" />
<Setter Target="TimetableGrid.ItemsPanel"
Value="{StaticResource ResourceKey=NarrowItemsPanelTemplate}" />
</VisualState.Setters>
</VisualState>
。