滚动条不可见 - Stack Pannel

时间:2014-10-15 05:49:34

标签: c# .net windows-store-apps windows-store

<StackPanel Name="CurrentInvoice" Margin="118,165,119,58" Opacity="100" Background="White">
        <TextBlock Name="Status" FontSize="16" Foreground="GreenYellow"/>
        <ListView Name="Invoices" Width="1000" HorizontalAlignment="Left" VerticalAlignment="Top" SelectionMode="None">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Height="35" HorizontalAlignment="Center" VerticalAlignment="Center" Width="1000">
                        <Border Background="#FF91C919" Width="102">
                            <TextBlock Text="{Binding TransactionHeaderId}" Margin="21,0,0,0" Foreground="White"  FontSize="30" Width="81" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Segoe UI" Height="35"></TextBlock>
                        </Border>
                        <Border Background="#FFF99B9B" Width="102">
                            <Button Foreground="White" Height="20" Width="55" Content="{Binding TransactionHeaderId}" Command="{Binding TestCommand}" Click="InvoiceOpen_Click" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="16,0,10,7" BorderBrush="{x:Null}">
                                <Button.Template>
                                    <ControlTemplate TargetType="Button">
                                        <Image Source="Assets/moreIcon.png"/>
                                    </ControlTemplate>
                                </Button.Template>
                            </Button>
                        </Border>
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackPanel>

以上编码用于显示堆栈面板内的项目,但我无法添加滚动条。我也使用了Scrollviewer。对此没有任何影响。所有溢出都被隐藏了。请找一个添加滚动条的方法。(垂直/水平)

2 个答案:

答案 0 :(得分:0)

    <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
 <StackPanel Name="CurrentInvoice" Margin="118,165,119,58" Opacity="100" Background="White">
    <TextBlock Name="Status" FontSize="16" Foreground="GreenYellow"/>
    <ListView Name="Invoices" Width="1000" HorizontalAlignment="Left" VerticalAlignment="Top" SelectionMode="None">
        <ListView.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal" Height="35" HorizontalAlignment="Center" VerticalAlignment="Center" Width="1000">
                    <Border Background="#FF91C919" Width="102">
                        <TextBlock Text="{Binding TransactionHeaderId}" Margin="21,0,0,0" Foreground="White"  FontSize="30" Width="81" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Segoe UI" Height="35"></TextBlock>
                    </Border>
                    <Border Background="#FFF99B9B" Width="102">
                        <Button Foreground="White" Height="20" Width="55" Content="{Binding TransactionHeaderId}" Command="{Binding TestCommand}" Click="InvoiceOpen_Click" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="16,0,10,7" BorderBrush="{x:Null}">
                            <Button.Template>
                                <ControlTemplate TargetType="Button">
                                    <Image Source="Assets/moreIcon.png"/>
                                </ControlTemplate>
                            </Button.Template>
                        </Button>
                    </Border>
                </StackPanel>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
 </StackPanel>
</ScrollViewer>

答案 1 :(得分:0)

将StackPanel放在ScrollViewer中,并将VerticalScrollBarVisibility和Horizo​​ntalScrollBarVisibility设置为可见。

<ScrollViewer VerticalScrollBarVisibility="Visible"  HorizontalScrollBarVisibility="Visible">
            <StackPanel Name="CurrentInvoice" Opacity="100" Background="White">
                <TextBlock Text="Test" Foreground="Black" FontSize="40"/>
                <TextBlock Text="Test" Foreground="Black" FontSize="40"/>
                <TextBlock Text="Test" Foreground="Black" FontSize="40"/>
                <TextBlock Text="Test" Foreground="Black" FontSize="40"/>
                <TextBlock Text="Test" Foreground="Black" FontSize="40"/>
                <TextBlock Text="Test" Foreground="Black" FontSize="40"/>
                <TextBlock Text="Test" Foreground="Black" FontSize="40"/>
                <TextBlock Text="Test" Foreground="Black" FontSize="40"/>
                <TextBlock Text="Test" Foreground="Black" FontSize="40"/>
                <TextBlock Text="Test" Foreground="Black" FontSize="40"/>
            </StackPanel>

        </ScrollViewer>

如果您不希望滚动条一直显示,请将这两个设置设置为自动。