在Microsoft Surface平台上使用WPF扩展器控件

发布于 2024-09-25 22:41:22 字数 106 浏览 5 评论 0原文

我正在尝试在表面应用程序中使用 Expander 控件。我看到它不是表面控件,因此应用程序编译并显示控件,但触点不起作用。

无论如何,我可以修改接触事件并使其在表面应用程序中工作吗?

I am trying to use the Expander control in the surface application. I have seen its not a surface control so application compiles and control shows up but the contacts are not working.

Is there anyway I can modify the contact events and make it work in surface applications.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

若沐 2024-10-02 22:41:22

为此,您所要做的就是更改 Expander 的模板以使用 Surface 控件而不是常规控件。

Expander 的默认模板可以在 http: //msdn.microsoft.com/en-us/library/ms753296.aspx

您需要更改的只是 ToggleButton:

<ToggleButton OverridesDefaultStyle="True"
              Template="{StaticResource ExpanderToggleButton}"
              IsChecked="{Binding IsExpanded, Mode=TwoWay, 
              RelativeSource={RelativeSource TemplatedParent}}">

更改为

<s:SurfaceToggleButton OverridesDefaultStyle="True"
                       Template="{StaticResource ExpanderToggleButton}"
                       IsChecked="{Binding IsExpanded, Mode=TwoWay, 
                       RelativeSource={RelativeSource TemplatedParent}}">

(省略结束标记)

这假设 s 绑定到 Surface XML 命名空间:

xmlns:s="http://schemas.microsoft.com/surface/2008"

To do that, all you have to do is change the Expander's template to use Surface controls instead of the regular controls.

The Expander's default template can be found at http://msdn.microsoft.com/en-us/library/ms753296.aspx.

All you need to change is the ToggleButton:

<ToggleButton OverridesDefaultStyle="True"
              Template="{StaticResource ExpanderToggleButton}"
              IsChecked="{Binding IsExpanded, Mode=TwoWay, 
              RelativeSource={RelativeSource TemplatedParent}}">

changes to

<s:SurfaceToggleButton OverridesDefaultStyle="True"
                       Template="{StaticResource ExpanderToggleButton}"
                       IsChecked="{Binding IsExpanded, Mode=TwoWay, 
                       RelativeSource={RelativeSource TemplatedParent}}">

(closing tags omitted)

This assumes s is bound to the Surface XML Namespace:

xmlns:s="http://schemas.microsoft.com/surface/2008"
诗酒趁年少 2024-10-02 22:41:22

我讨厌破坏这样一个古老的话题,但这是谷歌的最佳结果,我找到了一个更适合我的解决方案。

GUI 加载后,我使用 VisualTreeHelper 在运行时递归生成所有 GUI 对象的 List。我的项目出于其他原因需要此 GUI 对象列表,但它也为我提供了一个非常简单的解决方案来为非 Surface 控件添加触摸支持。

viewObjectList.ForEach(x =>
        {
            var temp = x as System.Windows.Controls.Primitives.ToggleButton;
            if (temp != null)
            {
                temp.IsManipulationEnabled = true;
                temp.TouchUp += TouchUpEvent;
            }
        });

遍历 GUI 对象列表,找到 ToggleButtons(Expander 的实际可点击部分),打开其触摸支持,并在 TouchUp 触发时(当用户抬起手指时)将事件绑定到它们。

private void TouchUpEvent(object sender, TouchEventArgs e)
    {
        if (TouchesOver.Count() == 1)
        {
            var temp = sender as System.Windows.Controls.Primitives.ToggleButton;
            temp.IsChecked = !temp.IsChecked;
        }
        e.Handled = false;
    }

I hate to necro such an old topic but this was the top google result and I found a solution that worked better for me.

After my GUI loads I use the VisualTreeHelper recursively to generate a List<DependencyObject> of all the GUI objects at runtime. My project required this GUI object list for other reasons, but it also gave me a very simple solution to adding Touch-support for non-Surface controls.

viewObjectList.ForEach(x =>
        {
            var temp = x as System.Windows.Controls.Primitives.ToggleButton;
            if (temp != null)
            {
                temp.IsManipulationEnabled = true;
                temp.TouchUp += TouchUpEvent;
            }
        });

Iterate through the list of GUI objects, find the ToggleButtons (the actual clickable part of the Expander), turn on their touch-support, and bind an event to them when TouchUp is fired (when a user lifts their finger).

private void TouchUpEvent(object sender, TouchEventArgs e)
    {
        if (TouchesOver.Count() == 1)
        {
            var temp = sender as System.Windows.Controls.Primitives.ToggleButton;
            temp.IsChecked = !temp.IsChecked;
        }
        e.Handled = false;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文