我有点期待我的ScrollViewer的子控件将MouseWheel事件自动备份到ScrollViewer,而事实并非如此.
我有一个带有ListBox的ScrollViewer.如果我手动将ListBox的宽度调整为小于ScrollViewer,MouseWheel将在所有ScrollViewer上工作,但当鼠标位于ListBox上方时无效.
这样做的标准方法是什么?我是否在ListBox上放置一个事件触发器来触发父事件上的事件?我在后面的代码中处理和重新路由事件吗?
把一个当我的鼠标滚轮不起作用ListBox的ScrollViewer.
ListBox这种事件会以某种方式"窃取"吗?
<ScrollViewer VerticalScrollBarVisibility="Auto" Style="{StaticResource myStyle}">
<ListBox>
<ListBoxItem>Test 1</ListBoxItem>
<ListBoxItem>Test 2</ListBoxItem>
<ListBoxItem>Test 3</ListBoxItem>
<ListBoxItem>Test 4</ListBoxItem>
<ListBoxItem>Test 5</ListBoxItem>
<ListBoxItem>Test 6</ListBoxItem>
<ListBoxItem>Test 7</ListBoxItem>
</ListBox>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)
编辑:按照Joel的要求,添加了我之所以这样做的原因..我这样做是因为我不喜欢ListBox内部ScrollViewer对我的布局做了什么.我有一个背景图片,除此之外,ListBox如下图所示:
替代文字http://robbertdam.nl/share/1.png
现在,当滚动条出现时,会发生以下情况:
替代文字http://robbertdam.nl/share/2.png
我创建了一个样式ScrollViewer,显示滚动条顶部的的ListBox项目内容.在ListBox项目的datatemplate中,我为滚动条保留了一些空间.
谢谢,Robbert Dam
我有一个显示项目的包装面板,但我不能让滚动条正常工作任何想法的错误是什么?
<ScrollViewer>
<ItemsControl Name="itemsControl">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel ItemWidth="{Binding ElementName=sizeSlider, Path=Value}"
FlowDirection="LeftToRight" Height="auto" Width="auto"
HorizontalAlignment="Left" Name="wrapPanel1"
VerticalAlignment="Top"
Margin="5"
>
</WrapPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
我在同一位置有一个TextBlock和一个文本框.根据用户所处的模式,我使一个可见,另一个折叠.这工作正常,但我怎样才能使Textblock可滚动?我想我应该使用ScrollViewer,但我不知道它为什么不起作用.我已经尝试过使用高度(自动和固定),但它不会滚动.我的xaml是这样的:
<ScrollViewer x:Name="detailsScroller" Height="285" Width="480" Canvas.Top="76" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<Canvas x:Name="infoCanvas" Width="478" >
<TextBlock x:Name="textblockInfo" TextWrapping="Wrap" Width="462" Height="197" Canvas.Left="8"/>
<TextBox x:Name="textboxInfo" TextWrapping="Wrap" Width="478" AcceptsReturn="True" Height="300" Visibility="Collapsed" />
</Canvas>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)
谢谢!
我正在尝试获得滚动查看器可以在垂直和水平方向上滚动的最大量,但我需要在布局更新的回调中执行此操作.这就是我目前正在做的事情:
viewer.ScrollToRight( );
doublehmax = viewer.HorizontalOffset;
viewer.ScrollToBottom( );
double vmax = viewer.VerticalOffset;
Run Code Online (Sandbox Code Playgroud)
但这会产生错误:"检测到Silverlight 2应用程序布局周期中的未处理错误.布局无法完成."
有没有办法即使在窗口调整大小等之后我还能可靠地获得滚动视图区域的最大水平和垂直偏移?
我想要的是: 我希望在我的Silverlight 4应用程序中有一个ScrollView,它与内容一起在Height中增长,但如果它会比它的容器更高,它会显示一个滚动条.
我发现的解决方案: 我发现很多问题,其中解决方案是拉伸Scrollviewer,但这不是我想要的.Scrollviewer应该尽可能小.
我的问题: 为了使滚动查看器顶部更加困难,可以找到一个标题,它是一个具有静态高度的堆栈面板.
解决方案Approch 1: 我首先尝试使用普通的XAML,但我无法弄清楚它应该如何工作.
<Grid Height="Auto" x:Name="myGrid" >
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Background="AliceBlue">
<!-- Dummy Header-->
</StackPanel>
<ScrollViewer Grid.Row="1" Height="Auto">
<Button Width="100" Height="50" Click="Button_Click" />
<!-- onClick the button will switch between height="600" and height="50"
Code:
private void Button_Click(object sender, RoutedEventArgs e)
{
if (sender is Button)
{
Button btn = (Button)sender;
btn.Height = (btn.Height == 50) ? 600 : 50 ;
}
}
--> …Run Code Online (Sandbox Code Playgroud) 问题:TextBox当我在里面输入大文本时,我无法在键入内部时看到我的指针TextBox
描述:
TextBox输入文本时,如果输入的文本很大,则应启用滚动.ScrollViewer仅显示TextBox高度内的内容ScrollViewer码:
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="Scroll Content Inside Textbox" Style="{StaticResource PhoneTextNormalStyle}" Margin="25,0,180,0"/>
</StackPanel>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ScrollViewer Height="200"
VerticalAlignment="Top">
<TextBox x:Name="txtBody"
Width="200"
AcceptsReturn="True"
/>
</ScrollViewer>
</Grid>
</Grid>
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建类似于macOS Finder列视图的触摸屏界面,这是一系列水平堆叠列表,其中每个列表都可以单独滚动(垂直),整个事物可以水平滚动,如下所示:

这是我的.NET 4.6.1"最小可行代码示例"来演示我正在做的事情:
前端:
<Window x:Class="TestNestedScroll.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestNestedScroll"
Title="MainWindow" Height="500" Width="800"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled" PanningMode="HorizontalOnly">
<ItemsControl ItemsSource="{Binding Columns}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" PanningMode="VerticalOnly">
<ItemsControl ItemsSource="{Binding Rows}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Rectangle Width="300" Height="100" Fill="Purple" Margin="20"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Window>
Run Code Online (Sandbox Code Playgroud)
后端:
using System.Collections.Generic;
using System.Linq;
using System.Windows;
namespace TestNestedScroll
{
public partial class MainWindow : Window
{
public class Row {}
public class Column { public …Run Code Online (Sandbox Code Playgroud) 这应该是一个非常简单的任务,但由于某种原因,我在WPF中遇到了很多问题.
这就是我想要发生的事情:我在窗口中有一堆控件,包括扩展器控件.当内容扩展到可见区域下方时,我想要为该窗口设置滚动条.此外,窗口不是固定宽度,可以最大化,调整大小等.
我尝试将ScrollViewer作为窗口中的第一个元素,但它无法正常工作.如果我将高度和宽度设置为自动,则不会滚动,如果我将其设置为特定设置,则会在窗口最大化时创建一个框.
任何帮助将不胜感激!
我有一个带有多个ListView控件的应用程序,其中要求ListView中的项目必须完全可见.应该永远不会在列表中显示部分ListViewItem.如果用户在最终显示部分项目的位置释放ScrollViewer,则列表应"快照"并自行更正,以便仅显示完整项目.
有没有人这样做过?我想我需要重载ListView和/或ScrollViewer才能执行此操作.我正在寻找有关如何处理此问题的建议.谢谢.
这是我的一个清单:
<ctrls:SnapList x:Name="PART_ProductList"
ScrollViewer.CanContentScroll="False"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ItemContainerStyle="{StaticResource ProductFinderItem}"
Canvas.Top="373" Canvas.Left="75"
Height="910" Width="900" >
<ctrls:SnapList.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard" />
</ItemsPanelTemplate>
</ctrls:SnapList.ItemsPanel>
<ctrls:SnapList.Template>
<ControlTemplate>
<ScrollViewer x:Name="Scroller" VerticalAlignment="Top" CanContentScroll="True" Style="{StaticResource VertScrollViewer}" Focusable="false" >
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</ctrls:SnapList.Template>
</ctrls:SnapList>
Run Code Online (Sandbox Code Playgroud) scrollviewer ×10
wpf ×6
c# ×4
silverlight ×3
xaml ×3
.net ×1
listbox ×1
listview ×1
mousewheel ×1
scroll ×1
textblock ×1
wpf-controls ×1
wrappanel ×1