【问题标题】:WP7: Button Tap event not firing, why?WP7:Button Tap 事件没有触发,为什么?
【发布时间】:2012-01-25 15:11:28
【问题描述】:

我正在为我的应用程序使用 WP7 'Mango' SDK 和 Phone Toolkit。我有一个控件,其中包含 ExpanderView。我正在为 ExpanderView 的标题使用下一个模板:

<toolkit:ExpanderView.HeaderTemplate>  
    <DataTemplate>  
        <StackPanel Orientation="Horizontal">  
            <TextBlock Text="{Binding Name}"/>  
            <Button Tap="ShowMoreTap">  
                <Button.Template>  
                    <ControlTemplate>  
                        <TextBlock Text="show more..."/>  
                    </ControlTemplate>  
                </Button.Template>  
            </Button>  
        </StackPanel>  
    </DataTemplate>  
</toolkit:ExpanderView.HeaderTemplate>  

背后的代码:

private void ShowMoreTap(object sender, System.Windows.Input.GestureEventArgs e)
{
    // Some logic here
}  

我不想在用户点击按钮时展开/折叠 ExpanderView,我需要一些特定的操作。问题是 ShowMoreTap 事件永远不会被触发。

有什么想法吗?
谢谢

【问题讨论】:

    标签: windows-phone-7 silverlight-toolkit


    【解决方案1】:

    According to the source code Tap 由 ExpanderView 处理导致展开(或折叠)

    显然,这个事件永远不会冒泡;它不是一个路由事件。

    我看到两个选项:

    1. 使用来自 codeplex 的源代码制作自定义版本的 ExpanderView 或
    2. 停止使用 ExpanderView,因为您不想展开任何内容。您可能可以更轻松地切换到另一个样式相似的控件。请记住:不要使用控件,因为它看起来像您想要的那样,使用它是因为它具有您需要的属性和行为。 WP7 允许您为任何控件设置样式。

    【讨论】:

    • 谢谢尔诺!实际上我不想拒绝该控件的展开/折叠选项。点击此按钮将向 ExpanderView 添加更多项目。之后,它将完全充当标准控件。将尝试制作定制版本。
    猜你喜欢
    • 1970-01-01
    • 2011-05-18
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    • 2021-05-27
    • 1970-01-01
    • 2013-03-01
    • 1970-01-01
    相关资源
    最近更新 更多