触摸:
鼠标:
我该如何在代码中告诉 ScrollViewer
开始使用触摸式滚动条?
以下是一个示例:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ScrollViewer Name="scrollViewer1" HorizontalScrollBarVisibility="Visible" >
<Image Stretch="UniformToFill">
<Image.Source>
<BitmapImage x:Name="bitmapImage1" UriSource="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png"></BitmapImage>
</Image.Source>
</Image>
</ScrollViewer>
</Grid>
并且:
public sealed partial class MainPage : Page
{
DispatcherTimer dispatcherTimer1 = new DispatcherTimer { Interval = TimeSpan.FromSeconds(5) };
bool SE;
public MainPage()
{
this.InitializeComponent();
dispatcherTimer1.Tick += DispatcherTimer1_Tick;
dispatcherTimer1.Start();
}
private void DispatcherTimer1_Tick(object sender, object e)
{
if (SE = !SE) bitmapImage1.UriSource = new Uri("https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/se/se-icon.png");
else bitmapImage1.UriSource = new Uri("https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png");
scrollViewer1.ChangeView(SE ? 1 : 0, SE ? 1 : 0, null);
}
}
如果您在触摸屏电脑上运行此程序,滚动条将初始为触摸模式。如果您随后用鼠标将光标移动到其上方,则它将变为鼠标模式。但是,如果您在滚动条被隐藏后再次进行触摸,则它将返回到触摸模式。
我希望以编程方式告诉它从一个模式切换到另一个模式。如何实现?如果唯一的方法是通过编辑模板,那么如何在不硬编码 the template 的情况下解决这个问题呢?只需修复需要修复的细节。明确一下:我想调用一个方法来切换模式:
void ChangeTo(bool mouse) { ... }
。(尽管失败了,强制使ScrollViewer始终处于一种模式也可以算是一种解决方法。)