你好,我希望当视力小于720时,如手机,我希望网格2低于网格1.我尝试了它的面板和自适应触发器,如下所示:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<RelativePanel >
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="VisualStateGroup">
<VisualState x:Name="NarrowView">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="0" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="Grid2.(RelativePanel.Below)" Value="Grid1"/>
<Setter Target="Grid1.(RelativePanel.Above)" Value="Grid2"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="WideView">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="720" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="Grid2.(RelativePanel.RightOf)" Value="Grid1"/>
<Setter Target="Grid1.(RelativePanel.LeftOf)" Value="Grid2"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" x:Name="Grid1" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBox Grid.Row="0" FontSize="20" PlaceholderText="NOME" Style="{StaticResource ResourceKey=TextBoxStyle}"/>
</Grid>
<Grid Grid.Column="1" x:Name="Grid2">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" FontSize="17" Text="Note" Foreground="#222222" Margin="20,15" ></TextBlock>
<TextBox Grid.Row="2" MaxLength="0" FontSize="17" Height="500" PlaceholderText="AGGIUNGI NOTA" Style="{StaticResource ResourceKey=TextBoxStyle}"></TextBox>
</Grid>
</Grid>
</RelativePanel>
</Grid>
但它不起作用。 谢谢
答案 0 :(得分:2)
您需要解决两件事:
1)要使VisualState正常工作,请将VisualStateManager置于根网格的第一个子节点下:
var graphClient = new ActiveDirectoryClient(new Uri(ConfigHelper.GraphServiceRoot), async () => await GetUserTokenAsync(cache));
var actualUser = await graphClient.Users.GetByObjectId(matchedUser.ObjectId).ExecuteAsync();
var actualGroup = (Group) await graphClient.Groups.GetByObjectId(matchedGroup.ObjectId).ExecuteAsync();
actualGroup.Members.Add(actualUser as DirectoryObject);
await graphClient.Context.SaveChangesAsync();
2)您不需要添加列,只需将两个网格放在RelativePanel下:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<VisualStateManager.VisualStateGroups>
......
</VisualStateManager.VisualStateGroups>
......
</Grid>
完成的xaml代码:
<RelativePanel>
<Grid x:Name="Grid1">
......
</Grid>
<Grid x:Name="Grid2">
......
</Grid>
</RelativePanel>
答案 1 :(得分:0)
如果有人关心,我找到了没有relativePanel的解决方案:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="VisualStateGroup">
<VisualState x:Name="NarrowView">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="0" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="text.(Grid.ColumnSpan)" Value="2" />
<Setter Target="text1.(Grid.ColumnSpan)" Value="2" />
<Setter Target="text2.(Grid.ColumnSpan)" Value="2" />
<Setter Target="text1.(Grid.Row)" Value="1" />
<Setter Target="text1.(Grid.Column)" Value="0" />
<Setter Target="text2.(Grid.Row)" Value="2" />
<Setter Target="text2.(Grid.Column)" Value="0" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="WideView">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="860" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="text.(Grid.ColumnSpan)" Value="1" />
<Setter Target="text1.(Grid.Row)" Value="0" />
<Setter Target="text1.(Grid.Column)" Value="1" />
<Setter Target="text2.(Grid.Row)" Value="1" />
<Setter Target="text2.(Grid.Column)" Value="1" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBox x:Name="text" PlaceholderText="NOME" />
<TextBlock x:Name="text1" Grid.Row="0" Grid.Column="1" Text="Note"></TextBlock>
<TextBox x:Name="text2" Grid.Row="1" Grid.Column="1" PlaceholderText="AGGIUNGI NOTA" ></TextBox>
</Grid>