【问题标题】:Action on both button press and release按钮按下和释放动作
【发布时间】:2011-12-06 21:10:14
【问题描述】:

我不能直截了当地说:我有一个按钮,我想要一个用于新闻事件的操作和一个用于发布的操作,我到处搜索但找不到答案。

KeyDownKeyUpMouseLeftButtonDown 不适用于 windows phone 7 上的按钮。

首先我尝试像这样组合GotFocusClick clickmode 发布:

(如您所见,我希望 Image1 在按下按钮时显示,并在释放按钮时隐藏)

xaml:

Button Click="button1_Click" ClickMode="Release" GotFocus="button1_GotFocus" Content="byt" Height="72" Margin="0,500,6,0" Name="button1" VerticalAlignment="Top"

    private void button1_GotFocus(object sender, RoutedEventArgs e)
    {
        Image1.Visibility = System.Windows.Visibility.Collapsed;
    }

    private void button1_Click (object sender, RoutedEventArgs e)
    {
        Image1.Visibility = System.Windows.Visibility.Visible;
    }

这只能工作一次,如果我在释放按钮时可以从按钮上松开焦点,则可以一直工作(也尝试搜索)

我尝试的另一件事是在按下按钮时更改点击模式,但也没有让它工作..

类似这样的:

    private void button1_Click (object sender, RoutedEventArgs e)
    {
        Image1.Visibility = System.Windows.Visibility.Collapsed;

        button1.SetValue(Button.ClickModeProperty, ClickMode.Release);
        Image1.Visibility = System.Windows.Visibility.Visible;
    }

(我知道第二个语法有问题)

不胜感激!

【问题讨论】:

    标签: c# xaml windows-phone-7


    【解决方案1】:

    MouseLeftButtonDown / MouseLeftButtonUp 在 WP7 上工作。显然不是最好的,但它们确实在设备上工作。

     <TextBlock x:Name="ApplicationTitle" MouseLeftButtonDown="ApplicationTitle_MouseLeftButtonDown" MouseLeftButtonUp="ApplicationTitle_MouseLeftButtonUp"
                       Style="{StaticResource PhoneTextNormalStyle}"
                       Text="MY APPLICATION" />
    

    您会看到 Down 被解雇,然后立即 Up。

     private void ApplicationTitle_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
            {
    
            }
    
            private void ApplicationTitle_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
            {
    
            }
    

    【讨论】:

    • 由于某种原因它不能与按钮一起使用??我在您编写的函数中添加了“对象发送者,System.Windows.Input.MouseButtonEventArgs e”...
    • 但我刚刚意识到我可以使用 TextBlock 代替,谢谢!!
    【解决方案2】:

    也许您只需要 MouseLeftButtonDown/Up。

    【讨论】:

      【解决方案3】:

      我用过

      Click="{x:Bind UpArrow_Click}" 
      ClickMode="Press" 
      PointerCaptureLost="Button_Release"
      

      在一个按钮上。当按钮被按下时UpArrow_Click事件发生...当按钮被释放时发生Button_Release事件

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多