【问题标题】:Scroll bar not Visible - Stack Pannel滚动条不可见 - 堆栈内存溢出
【发布时间】:2014-12-10 02:29:15
【问题描述】:
<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。没有效果。所有溢出都被隐藏了。请帮我找到一种添加滚动条的方法。(垂直/水平)

【问题讨论】:

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


    【解决方案1】:
        <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>
    

    【讨论】:

    • 设置 Horizo​​ntalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
    【解决方案2】:

    将 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>
    

    如果您不希望滚动条一直可见,请将这两个设置设置为“自动”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-25
      • 2012-03-24
      • 1970-01-01
      • 1970-01-01
      • 2011-07-09
      • 1970-01-01
      • 2019-05-18
      • 1970-01-01
      相关资源
      最近更新 更多