无法将网格中的XAML元素移动到另一个单元格

时间:2014-02-20 04:03:48

标签: xaml windows-runtime

在我的Windows商店应用程序中,我正在尝试使用两个ListView,当显示器足够宽时并排,并在显示器很薄时垂直堆叠。

我正在尝试使用2x2网格,默认网格就像这样

<Grid Grid.Row="1" HorizontalAlignment="Stretch" Margin="0,0,0,20">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" x:Name="FromUnitSelectorColumn" />
                    <ColumnDefinition Width="*" x:Name="ToUnitSelectorColumn" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" x:Name="FromUnitSelectorRow" />
                    <RowDefinition Height="auto" x:Name="ToUnitSelectorRow" />
                </Grid.RowDefinitions>
                <ListView Name="FromUnitSelector" Header="Converting From " Margin="0,0,10,0" Grid.Row="0" Grid.Column="0">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="auto"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="auto" />
                                </Grid.RowDefinitions>
                                <Border BorderBrush="{x:Null}" Height="40" Width="40" Margin="5,0,0,0" Background="Beige">
                                    <TextBlock Text="{Binding symbol}" HorizontalAlignment="Center" VerticalAlignment="Center" TextTrimming="Clip" FontSize="10"/>
                                </Border>
                                <Border BorderBrush="{x:Null}" Height="40" Margin="5,0,0,0" Grid.Row="0" Grid.Column="1">
                                    <TextBlock Text="{Binding name}" HorizontalAlignment="Stretch" TextAlignment="Center" VerticalAlignment="Center" FontSize="14" TextWrapping="Wrap"/>
                                </Border >
                            </Grid>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
                <ListView Name="ToUnitSelector" Header="To " Margin="10,0,0,0" Grid.Row="0" Grid.Column="1">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="auto"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="auto" />
                                </Grid.RowDefinitions>
                                <Border BorderBrush="{x:Null}" Height="40" Width="40" Margin="5,0,0,0" Background="Beige">
                                    <TextBlock Text="{Binding symbol}" HorizontalAlignment="Center" VerticalAlignment="Center" TextTrimming="Clip"  FontSize="10"/>
                                </Border >
                                <Border BorderBrush="{x:Null}" Height="40" Margin="5,0,0,0" Grid.Row="0" Grid.Column="1">
                                    <TextBlock Text="{Binding name}"  HorizontalAlignment="Stretch" TextAlignment="Center" VerticalAlignment="Center" FontSize="14" TextWrapping="Wrap"/>
                                </Border>
                            </Grid>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </Grid>

我试图在我的瘦视觉状态中将两个ListViews垂直堆叠在一起

<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ToUnitSelectorColumn" Storyboard.TargetProperty="Width">
    <DiscreteObjectKeyFrame KeyTime="0" Value="auto" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ToUnitSelectorRow" Storyboard.TargetProperty="Height">
    <DiscreteObjectKeyFrame KeyTime="0" Value="*" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ToUnitSelector" Storyboard.TargetProperty="Grid.Row">
    <DiscreteObjectKeyFrame KeyTime="0" Value="1" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ToUnitSelector" Storyboard.TargetProperty="Grid.Column">
    <DiscreteObjectKeyFrame KeyTime="0" Value="0" />
</ObjectAnimationUsingKeyFrames>

但是当我测试它时,我得到了这个异常“WinRT信息:无法解析指定对象上的TargetProperty Grid.Row。”

将第二个ListView更改为另一行和列需要做什么?我意识到使用stackpanel我可以简单地改变方向,但我需要它在网格中,所以它尽可能地延伸。

1 个答案:

答案 0 :(得分:0)

对于如此剧烈的布局更改,有时只需要有两个不同的布局,并使用模板或隐藏/显示这些布局的容器来切换它们。