2

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.

K Singh
  • 1,710
  • 1
  • 17
  • 32

2 Answers2

3

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"
robertos
  • 1,810
  • 10
  • 12
0

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;
    }
Chakrava
  • 823
  • 7
  • 10