我正在构建用于在布局中缩放和平移的 SL 应用程序。一切正常,除了当我使用鼠标滚轮放大时,在一些缩放滚动条开始使用鼠标滚轮之后,我可以滚动而不是缩放。如果我将滚动条放在末尾或开头,我只能再次缩放。如何防止滚动查看器使用鼠标滚轮?我希望只能通过轮操作变焦。先感谢您!
这是我缩放内容时的 MouseWheel 方法代码:
protected override void OnMouseWheel(MouseWheelEventArgs e)
{
base.OnMouseWheel(e);
if (e.Delta > 0)
{
this.aniScaleX.To += 0.2;
this.aniScaleY.To += 0.2;
this.sbScale.Begin();
}
else if (e.Delta < 0 && (this.aniScaleX.To > 1 && this.aniScaleY.To > 1))
{
this.aniScaleX.To -= 0.2;
this.aniScaleY.To -= 0.2;
this.sbScale.Begin();
}
Sizer.Width = Board.ActualWidth * (double)this.aniScaleX.To;
Sizer.Height = Board.ActualHeight * (double)this.aniScaleY.To;
Run Code Online (Sandbox Code Playgroud) 我有ScrollViewer一个StackPanel包含图像.是否可以在ScrollViewer/StackPanel中选择项目?
<ScrollViewer x:Name="Gallery" Grid.Column="1" Grid.Row="0"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Visible" >
<StackPanel x:Name="GalleryStack"/>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud) WinPhone 7.1
在ScrollViewer中,我有一个包含大约500个字符串的堆栈面板.我想将堆栈面板从代码滚动到某个偏移量.我试过这个:
for (int i = 0; i < 500; i++)
{
tb = new TextBlock();
tb.Text = "String #" + i.ToString();
this.stackPanel1.Children.Add(tb);
}
this.scrollViewer1.ScrollToVerticalOffset(200);// scroll to offset 200
this.scrollViewer1.UpdateLayout();
Run Code Online (Sandbox Code Playgroud)
但它根本不滚动.
我究竟做错了什么?
谢谢
donescamillo
我有一个用scrollviewer包装的堆栈面板。在堆栈面板内部,我有一些网格,而在网格内部,又有堆栈面板,MahApps Metro还提供了一些磁贴控件。
如果我拖动滚动条,scrollviewer可以正常工作。但鼠标滚轮不起作用。可能是某些控件正在窃取鼠标滚轮操作,但我无法确定哪一个。我试着在滚动条上滚动鼠标滚轮。但仍然无法正常工作。
<ScrollViewer x:Name="TS" Grid.Row="1" HorizontalAlignment="Stretch" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled" CanContentScroll="True" PanningMode="HorizontalOnly" SnapsToDevicePixels="True" Background="Transparent">
<StackPanel x:Name="TilesPanel" VerticalAlignment="Top" HorizontalAlignment="Stretch" Orientation="Horizontal">
<StackPanel.Resources>
<Style TargetType="{x:Type Grid}">
<Setter Property="Margin" Value="0,50,0,0"/>
</Style>
</StackPanel.Resources>
<Separator Background="{x:Null}" Width="110"></Separator>
<Grid>
<StackPanel>
<StackPanel Orientation="Horizontal">
<StackPanel.Resources>
<Style TargetType="{x:Type Grid}">
<Setter Property="Margin" Value="10,0,0,0"/>
</Style>
</StackPanel.Resources>
<Grid Height="260">
<StackPanel>
<StackPanel.Resources>
<Style TargetType="{x:Type StackPanel}">
<Setter Property="Margin" Value="0,0,0,10"/>
</Style>
</StackPanel.Resources>
<StackPanel Width="247" Height="119">
<Custom:Tile x:Name="Mail" Margin="0" Width="auto" d:LayoutOverrides="Height">
<Image Stretch="Fill" Source="Res/AppTiles/Mail.png"/>
</Custom:Tile>
</StackPanel>
//and it goes on like this//
</grid>
</stackpanel>
<Separator Background="{x:Null}" Width="50"/>
</Grid> …Run Code Online (Sandbox Code Playgroud) 我正在构建一个适用于Windows Phone 8.1的应用程序,我的滚动查看器会在您发布滚动后继续回到顶部.它就像我拖下来一样,当我释放它时,它会快速回到顶部.
<ScrollViewer Margin="10,0,10,-1024" Height="1124" VerticalAlignment="Top"
VerticalScrollBarVisibility="Visible" VerticalScrollMode="Enabled"
AllowDrop="False" BringIntoViewOnFocusChange="True"
HorizontalScrollMode="Disabled" IsHoldingEnabled="True" >
<Grid Grid.Row="1" x:Name="ContentRoot" Height="468" Width="386" >
<TextBlock HorizontalAlignment="Left" Margin="64,326,0,0"
TextWrapping="Wrap" VerticalAlignment="Top" Foreground="White"
FontSize="16" Width="307" Height="68" >
<Run Foreground="#FFFF6767" Text="Single Phase "/>
<Run Foreground="#FFFF6767" Text="Amperes "/>
<Run Text="= "/>
<Run Text="(746 x Horsepower) / (Volts x Efficiency x Power Factor"/>
<Run Text=")"/>
</TextBlock>
</Grid>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud) 我尝试在窗口中显示图像:
<Window x:Class="Problem.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<DockPanel>
<StackPanel Orientation="Vertical">
<ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible">
<Image Source="cat.jpg" Stretch="Uniform">
<Image.LayoutTransform>
<RotateTransform Angle="90" />
</Image.LayoutTransform>
</Image>
</ScrollViewer>
</StackPanel>
</DockPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
其中cat.jpg是1920x1080的图像.
结果如下:

如您所见,VerticalScrollbar已禁用,但我看不到完整的猫头.而且,HorisontalScrollBar是Invisible.
我的问题是:如何启用滚动条以滚动我的图像?
scrollviewer ×6
c# ×4
image ×2
stackpanel ×2
wpf ×2
xaml ×2
mousewheel ×1
scrollbar ×1
silverlight ×1
wpf-4.0 ×1
zooming ×1