我在理解如何构建Hub控件时遇到了一些问题。 我想要理解的主要思想是如何构建一个自定义控件,它允许执行一些手势,而不会阻止内部控件。
使用Hub
控制我可以按Button
并查看其回调(颜色和大小更改),然后向左移动指针滑动Hub
控件。
对于这个如此愚蠢的问题感到抱歉,但我没有足够的经验来自己找到任何回复。提前感谢任何建议。
答案 0 :(得分:0)
主要问题与使用GestureRecognizer
有关。
我已经修复了我的问题,拒绝使用GestureRecognizer
并开始在主容器上使用Manipulation Events。
简化的模板代码:
<Style TargetType="my:CustomHub">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="my:CustomHub">
<Grid x:Name="RootGrid">
<ContentPresenter x:Name="MainPresenter"
Content="{TemplateBinding Content}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Control的代码隐藏:
public sealed class CustomHub
{
public FrameworkElement Container { get; set; }
public MainView()
{
this.InitializeComponent();
}
private void InitGestureInteraction()
{
this.Container = (FrameworkElement)GetTemplateChild("RootGrid");
this.Container.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateRailsX;
this.Container.ManipulationStarted += (s, e) =>
{
};
this.Container.ManipulationDelta += (s, e) =>
{
var x = e.Cumulative.Translation.X;
// implementation of moving
};
this.Container.ManipulationCompleted += (s, e) =>
{
var x = e.Cumulative.Translation.X;
// implementation of moving
};
}
}