UWP Xaml相对面板,拉伸和其他元素

时间:2016-12-10 08:11:48

标签: xaml uwp uwp-xaml

我创建UWP应用程序并使用RelativePanel。 我使用相对panel.alignwithright,顶部,左侧,底部面板拉伸宽度到listview。 但是在listview右侧添加其他元素(例如Stackpanel)后,其他面板不会在页面中查看。 所以我删除了relativePanel.AlignWithRight,在这种情况下不能在listview中展宽。

我该怎么办?

I want this shape to come out.

Now RelativePanel

代码:

<RelativePanel x:Name="Information" Grid.Row="1">
            <ListView x:Name="MyList"
                      RelativePanel.AlignBottomWithPanel="True"
                      RelativePanel.AlignTopWithPanel="True"
                      RelativePanel.AlignRightWithPanel="True"
                      RelativePanel.AlignLeftWithPanel="True">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <userControl:SpendListItem_Template Tapped="SpendListItem_Template_Tapped" ></userControl:SpendListItem_Template>
                    </DataTemplate>
                </ListView.ItemTemplate>

                <ListView.ItemContainerStyle>
                    <Style TargetType="ListViewItem">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
                        <Setter Property="Margin" Value="10,0,10,10"></Setter>
                    </Style>
                </ListView.ItemContainerStyle>
            </ListView>

            <StackPanel x:Name="TotalInformation" RelativePanel.RightOf="MyList" Width="100">
                <TextBlock>Test Data</TextBlock>
            </StackPanel>
        </RelativePanel>

1 个答案:

答案 0 :(得分:2)

我很确定你不能通过设置一些RelativePanel附加属性来在纯XAML中执行此操作,但是您可以处理RelativePanel的SizeChanged事件并以编程方式设置ListView的宽度。这是一个班轮:

private void Information_SizeChanged(object sender, SizeChangedEventArgs e)
{
     MyList.Width = Information.ActualWidth - TotalInformation.ActualWidth;
}
<RelativePanel x:Name="Information" Grid.Row="1" SizeChanged="Information_SizeChanged">
        <ListView x:Name="MyList">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <userControl:SpendListItem_Template Tapped="SpendListItem_Template_Tapped" ></userControl:SpendListItem_Template>
                </DataTemplate>
            </ListView.ItemTemplate>

            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
                    <Setter Property="Margin" Value="10,0,10,10"></Setter>
                </Style>
            </ListView.ItemContainerStyle>
        </ListView>

        <StackPanel x:Name="TotalInformation" RelativePanel.RightOf="MyList" Width="100">
            <TextBlock>Test Data</TextBlock>
        </StackPanel>
 </RelativePanel>