使用列表框重叠控件

时间:2014-01-20 10:59:25

标签: windows xaml windows-runtime windows-store-apps winrt-xaml

我正在尝试创建一个自动完成框但是它会继续移动我的网格/堆栈面板中的项目,而我希望列表框与控件重叠,我该如何防止这种情况发生?我还想说控件可能出现在文本框上方。提前致谢。 Without Items Not overlapping with items

XAML:

<Page
    x:Class="test.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:test"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:mmppf="using:Microsoft.PlayerFramework"
    xmlns:ab="using:AutoCompleteBox"
    mc:Ignorable="d">

    <Grid Name="rootGrid">

        <ScrollViewer Grid.Row="2" Grid.Column="0" x:Name="panelScrollViewer" Height="Auto" VerticalScrollBarVisibility="Auto" HorizontalScrollMode="Disabled" HorizontalAlignment="Stretch" VerticalAlignment="Top" ZoomMode="Disabled" MaxZoomFactor="1" MinZoomFactor="1">

            <StackPanel Name="contentPanel" Orientation="Vertical" Margin="20,0" HorizontalAlignment="Stretch">

                <mmppf:MediaPlayer Name="player" Background="Black" Margin="0,0,0,40" Height="Auto" Width="Auto" VerticalAlignment="Top" Visibility="Collapsed"/>

                <TextBox Name="autocomplete" Grid.Row="1" VerticalAlignment="Top" HorizontalAlignment="Stretch"/>

                <ListBox Name="autoCompleteListbox" Grid.Row="0" 
                         ScrollViewer.VerticalScrollBarVisibility="Auto"/>

                <StackPanel Name="menuPanel" Orientation="Vertical" HorizontalAlignment="Center">
                    <!--Contains Rows of stack panels with buttons-->
                </StackPanel>

                <ProgressRing Name="prLoading" Width="100" Height="100" Margin="50" Foreground="White" Visibility="Collapsed"/>

                <Grid Name="cv">
                    <!--more controls-->
                </Grid>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</Page>

注意:自动填充文本框是一个将在其下方显示列表框的对象。我也找到了解决方法,但如果有更好的方法,请建议。

解决方案:

<Page
    x:Class="test.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:test"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:mmppf="using:Microsoft.PlayerFramework"
    xmlns:ab="using:AutoCompleteBox"
    mc:Ignorable="d">

    <Grid Name="rootGrid">

        <ScrollViewer Grid.Row="1" Grid.Column="0" x:Name="panelScrollViewer" Height="Auto" VerticalScrollBarVisibility="Auto" HorizontalScrollMode="Disabled" HorizontalAlignment="Stretch" VerticalAlignment="Top" ZoomMode="Disabled" MaxZoomFactor="1" MinZoomFactor="1">

            <StackPanel Name="contentPanel" Margin="20,0" HorizontalAlignment="Stretch">
                <StackPanel Orientation="Vertical" HorizontalAlignment="Center">
                    <mmppf:MediaPlayer x:Name="player" Background="Black" Margin="0,0,0,40" Height="Auto" Width="Auto" VerticalAlignment="Top" Visibility="Collapsed"/>

                    <TextBox x:Name="autocomplete" VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
                </StackPanel>

                <Grid>
                    <StackPanel Margin="0" Orientation="Vertical" Grid.Row="1">
                        <StackPanel Name="menuPanel" Orientation="Vertical" HorizontalAlignment="Center">
                            <!--Contains Rows of stack panels with buttons-->
                        </StackPanel>

                        <ProgressRing Name="prLoading" Width="100" Height="100" Margin="50" Foreground="White" Visibility="Collapsed"/>

                        <Grid Name="cv">
                            <!--more controls-->
                        </Grid>
                    </StackPanel>
                    <ListBox Name="autoCompleteListbox" Grid.Row="0" 
                             VerticalAlignment="Top"
                             ScrollViewer.VerticalScrollBarVisibility="Auto"/>
                </Grid>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</Page>

0 个答案:

没有答案