Windows Phone应用程序状态&相机

时间:2013-08-11 13:31:10

标签: windows vb.net windows-phone-8 camera back-stack

好的,所以我使用下面的代码在我的应用程序中显示相机,效果很好!问题是当我离开并使用后台回到应用程序时,相机不会显示,直到我手动调用代码。

如何让它自动显示?

提前感谢Youuu

Dim cam As New Microsoft.Devices.PhotoCamera()

Public Sub New()
    InitializeComponent()
    SupportedOrientations = SupportedPageOrientation.Portrait
End Sub

Private Sub opening() Handles Me.Loaded
    cam = New Microsoft.Devices.PhotoCamera()
    viewfinderBrush.RelativeTransform = New CompositeTransform() With {.CenterX = 0.5, .CenterY = 0.5, .Rotation = 90}
    viewfinderBrush.SetSource(cam)
End Sub


Private Sub Closing() Handles Me.Unloaded
    cam.Dispose()


End Sub

1 个答案:

答案 0 :(得分:0)

修复了我自己的问题,只使用了受保护的覆盖子:)

喜欢这样

Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
    MyBase.OnNavigatedTo(e)
    cam = New Microsoft.Devices.PhotoCamera()
    viewfinderBrush.RelativeTransform = New CompositeTransform() With {.CenterX = 0.5, .CenterY = 0.5, .Rotation = 90}
    viewfinderBrush.SetSource(cam)
End Sub

Protected Overrides Sub OnNavigatedFrom(e As NavigationEventArgs)
    MyBase.OnNavigatedFrom(e)

    If cam IsNot Nothing Then
        cam.Dispose()
        cam = Nothing
    End If
End Sub