我们正在为Windows平板电脑编写应用程序。我创建了一个自定义控件,它使用SurfaceScrollViewer
在窗口右侧呈现垂直和可滚动列表。该控件使用Adorner将自身添加到Window的adorner层,以便可以在窗口内容的顶部进行渲染。
它非常好用,但表面滚动查看器只会滚动鼠标滚轮或滚动条。我希望能够隐藏滚动条并依靠用户通过触摸拖动列表,但这拒绝工作。我们已经在这个项目的其他地方使用了SurfaceScrollViewer
控件,这个工作正常,所以我猜这个问题是由于控件是如何构建的,还是因为它在AdornerLayer中?与Surface注册触摸有什么关系?奇怪的是,列表中的SurfaceButton
控件运行正常。
非常感谢任何帮助或建议。这基本上是自定义控件。我已经删除了一些绑定的碎片以减小尺寸,并且我添加了周围的Window / AdornerLayer / Adorner元素以将其置于上下文中。
编辑 - 实际上,装饰器已添加到Grid的装饰层中,该网格是Window的子级。我已经更新了下面的XAML。
<Window x:Name="Main">
<Grid>
<AdornerDecorator>
<!-- Adorner layer added to Window in code-behind -->
<AdornerLayer>
<Adorner>
<!-- Custom Control Starts Here -->
<Grid x:Name="root" Visibility="Collapsed" Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=Window}}" Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType=Window}}">
<Controls:SurfaceButton x:Name="btnCloser" Opacity="0" Background="White"/>
<Grid x:Name="menu" Width="400" HorizontalAlignment="Right" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="20"/>
<RowDefinition />
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<Border Opacity="0.75" BorderThickness="0" Background="Black" Grid.RowSpan="5" />
<TextBlock Text="{TemplateBinding Title}" FontSize="24" Grid.Row="1" Foreground="White" HorizontalAlignment="Center" Margin="10"/>
<Controls:SurfaceScrollViewer Grid.Row="3" Margin="5" Elasticity="0.0, 0.5" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<ItemsControl x:Name="items" Background="Transparent" ItemsSource="{TemplateBinding MenuItems}">
<ItemsControl.Style>
<Style>
<Setter Property="ItemsControl.ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemsControl.ItemTemplate">
<Setter.Value>
<DataTemplate>
<Controls:MyButton HorizontalContentAlignment="Center" Margin="3" Content="(Bound Stuff)" Background="(Bound Stuff)"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</ItemsControl.Style>
</ItemsControl>
</Controls:SurfaceScrollViewer>
</Grid>
</Grid>
</Adorner>
</AdornerLayer>
</AdornerDecorator>
</Grid>
</Window>
答案 0 :(得分:1)
好的 - 我深究了它。我意识到答案是在这个项目中多次出现的答案,但我时不时都会忽略它。也许这次它会永远陷入其中!
问题是ItemsControl。它不是Surface控件,因此它与Surface控件的效果不佳。我认为基本上会发生的事情是Surface控件倾向于在其他任何事物发生之前吞噬事件 - 或者可能是反过来。
无论如何,我用下面的SurfaceListBox替换它,这已经有了一个好处!
<Controls:SurfaceListBox x:Name="items" Margin="5" Grid.Row="3" Background="Transparent" ItemsSource="{TemplateBinding MenuItems}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Hidden">
<Controls:SurfaceListBox.Resources>
<Converters:PropertyNameReflectionConverter x:Key="ButtonContentConverter"/>
<Converters:SelectedItemBackgroundConverter x:Key="ButtonBackgroundConverter"/>
</Controls:SurfaceListBox.Resources>
<Controls:SurfaceListBox.ItemContainerStyle>
<Style TargetType="Controls:SurfaceListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:SurfaceListBoxItem}">
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Controls:SurfaceListBox.ItemContainerStyle>
<Controls:SurfaceListBox.ItemTemplate>
<DataTemplate DataType="Controls:MyButton">
<Controls:MyButton HorizontalContentAlignment="Center" Margin="3" Background="(Bound Stuff)" Content="(Bound Stuff)"/>
</DataTemplate>
</Controls:SurfaceListBox.ItemTemplate>
</Controls:SurfaceListBox>
答案 1 :(得分:0)
问题不在于ItemsControl而是SurfaceScrollViewer本身,因为您允许通过拖动滚动触摸/鼠标将SurfaceScrollViewer的PanningMode设置为“None”以外的其他设置。