ToggleButton在触摸设备上的行为有所不同

时间:2013-06-14 15:36:20

标签: c# xaml windows-8 windows-runtime

我在这里有一段XAML代码:

<ToggleButton x:Name="ColorPickerButton" 
                          Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Style="{StaticResource Segment0}" 
                          Checked="ColorPickerChecked" 
                          Unchecked="ColorPickerUnchecked">
                <ToggleButton.Transitions>
                    <TransitionCollection>
                        <EntranceThemeTransition FromHorizontalOffset="100" FromVerticalOffset="100"/>
                    </TransitionCollection>
                </ToggleButton.Transitions>
            </ToggleButton>

它在我的电脑上工作正常;通过正常工作,我的意思是当我点击ColorPickerChecked时正确调用方法ColorPickerUncheckedToggleButton。但是,在触摸设备(Microsoft Surface)上,根本不会调用这些方法。但是,如果我将其添加到XAML中,则会正确引发事件Tapped。现在,这是在引发Tapped事件时调用的方法:

private void ColorPickerButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            var s = sender as ToggleButton;
            if(s != null)
                s.IsChecked = !s.IsChecked;
        }

我觉得有点草率。为什么它的表现不同?这里有什么我想念的吗?我记得在其他应用程序中使用ToggleButton,在我的记忆中它似乎工作得很好......但不是在这里!

干杯

1 个答案:

答案 0 :(得分:1)

我怀疑你的一个ToggleButton容器控件正在干扰这些事件。

我在一个简单的容器中(在StackPanel内的Grid内)尝试了上面的xaml代码,CheckedUnchecked事件为我开火。

相关问题