XAML固定横幅在可滚动区域之上

时间:2015-09-05 19:24:08

标签: xaml

我试图在窗口中添加一个固定的横幅到我的页面,我很难过。

这就是我想要实现的目标:我想要一个漂浮在窗口顶部的横幅(对于广告),然后我想将其余内容放在可滚动区域中。第一项应该是textBlock,然后是textBox,然后是按钮。

http://i.imgur.com/uJiD1wE.png

这是我现在获得的代码,除了滚动外,它看起来正确。帮助将不胜感激。

<Page
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App2"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Universal="using:Microsoft.AdMediator.Universal"
    x:Class="App2.MainPage"
    mc:Ignorable="d" RequestedTheme="Dark">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <StackPanel Grid.RowSpan="3">
            <Universal:AdMediatorControl x:Name="AdMediatorName" Height="90" Id="AdMediator-Id" Margin="10,0"/>
            <ScrollViewer x:Name="myScrollViewer"  VerticalScrollMode="Enabled">
                <StackPanel Grid.RowSpan="2">
                    <TextBlock x:Name ="outputConsole" FontSize="15" RenderTransformOrigin="0.5,0" TextWrapping="WrapWholeWords" Margin="0,0,10,0" FontFamily="Consolas" IsTextSelectionEnabled="True">
                        <TextBlock.RenderTransform>
                            <CompositeTransform/>
                        </TextBlock.RenderTransform>
                        <TextBlock.Projection>
                            <PlaneProjection/>
                        </TextBlock.Projection>
                        <Run/>
                        <LineBreak/>
                        <Run/>
                    </TextBlock>
                    <TextBox x:Name="inputConsole" FontSize="20" KeyUp="inputKeyUp" Margin="0,0,10,0" FontFamily="Consolas" IsTapEnabled="True" IsTextPredictionEnabled="True"/>
                    <Button x:Name="submitButton" Content="Submit" Click="submitButtonClick"/>
                </StackPanel>
            </ScrollViewer>
        </StackPanel>

    </Grid>
</Page>

2 个答案:

答案 0 :(得分:0)

我明白了。我只需要将它直接放在网格中。对不起,还在学习XAML。

答案 1 :(得分:0)

你刚回答了你的问题。你必须做这样的事情,

    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
    <Grid.RowDefinitions>
        <RowDefinition Height="50"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <StackPanel Grid.Row="0" Orientation="Horizontal"><TextBlock x:Name ="outputConsole" FontSize="15" RenderTransformOrigin="0.5,0" TextWrapping="WrapWholeWords" Margin="0,0,10,0" FontFamily="Consolas" IsTextSelectionEnabled="True">
                    <TextBlock.RenderTransform>
                        <CompositeTransform/>
                    </TextBlock.RenderTransform>
                    <TextBlock.Projection>
                        <PlaneProjection/>
                    </TextBlock.Projection>
                    <Run/>
                    <LineBreak/>
                    <Run/>
                </TextBlock>
                <TextBox x:Name="inputConsole" FontSize="20" KeyUp="inputKeyUp" Margin="0,0,10,0" FontFamily="Consolas" IsTapEnabled="True" IsTextPredictionEnabled="True"/>
                <Button x:Name="submitButton" Content="Submit" Click="submitButtonClick"/>
    </StackPanel>  

    <ScrollViewer Grid.Row="1">

    </ScrollViewer>