为什么重新激活后滑块事件会停止?

时间:2015-09-08 10:25:08

标签: silverlight windows-phone-8.1 win-phone-silverlight-8.1

我正在使用Windows Phone 8.1 Silverlight应用程序,该应用程序在页面上具有各种控件的实例,按钮,复选框,单选按钮等,以及滑块。

每个控件都添加了一个事件处理程序,如下所示,此示例特定于滑块,但其他控件只是替换控件类型和处理的实际事件:

static void instrumentSlider(Slider slider)
{
    Logger.Logger.LogMessage("instrumentSlider() - Called for: [" + slider + "]");

    slider.ManipulationCompleted -= new EventHandler<ManipulationCompletedEventArgs>(slider_ManipulationCompleted);
    slider.ManipulationCompleted += new EventHandler<ManipulationCompletedEventArgs>(slider_ManipulationCompleted);
}

static void slider_ManipulationCompleted(object sender, ManipulationCompletedEventArgse)
{
    try
    {
        Logger.Logger.LogMessage("slider_ManipulationCompleted() - Called for: [" + sender + "]");

        if (sender is Slider)
        {
            Slider slider = (Slider)sender;
            // Do stuff...
        }
    }
    catch (Exception ex)
    {
        Logger.Logger.LogException(ex);
    }
}

我可以使用Visual Studio 2013将应用程序下载到手机上,一切都按预期工作,当我按下按钮或移动滑块时,我会看到我希望看到的日志消息。

在某些时候,我不小心按了手机上的相机按钮,我的应用程序被停用,相机应用程序被激活。我切换回我的应用程序,除了滑块之外的所有控件都会继续生成事件!

我在这里缺少什么?我已经为滑块尝试了几个事件,操作已完成,焦点丢失,值已更改,并且在重新激活应用程序后它们都停止传递,但所有其他控件的事件仍在传递中。

更新为包含定义控件的XAML片段:

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <Slider Height="84" HorizontalAlignment="Left" Margin="37,243,0,0" Name="slider1" VerticalAlignment="Top" Width="383" />
        <Button Content="Button" Height="72" HorizontalAlignment="Left" Margin="27,18,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" RenderTransformOrigin="0.531,-0.222" />
        <CheckBox Content="CheckBox" Height="72" HorizontalAlignment="Left" Margin="241,17,0,0" Name="checkBox1" VerticalAlignment="Top" RenderTransformOrigin="0.509,0.181" />
        <HyperlinkButton Content="HyperlinkButton" Height="30" HorizontalAlignment="Left" Margin="27,110,0,0" Name="hyperlinkButton1" VerticalAlignment="Top" Width="200" />
        <ListBox Height="103" HorizontalAlignment="Left" Margin="37,342,0,0" Name="listBox1" VerticalAlignment="Top" Width="383" RenderTransformOrigin="0.499,1.408">
            <ListBoxItem Content="ListItem1" />
            <ListBoxItem Content="ListItem2" />
            <ListBoxItem Content="ListItem3" />
        </ListBox>
        <RadioButton Content="RadioButton" Height="72" HorizontalAlignment="Left" Margin="241,73,0,0" Name="radioButton1" VerticalAlignment="Top" IsChecked="True" />
        <RadioButton Content="RadioButton" Height="72" HorizontalAlignment="Left" Margin="241,126,0,0" Name="radioButton2" VerticalAlignment="Top" RenderTransformOrigin="0.528,0.056" />
        <RadioButton Content="RadioButton" Height="72" HorizontalAlignment="Left" Margin="241,171,0,0" x:Name="radioButton3" VerticalAlignment="Top" RenderTransformOrigin="0.503,1.837" />
        <TextBox Height="72" HorizontalAlignment="Left" Margin="37,445,0,0" Name="textBox1" Text="TextBox" VerticalAlignment="Top" Width="383" />
    </Grid>

0 个答案:

没有答案