2014-01-31 18 views
0
<phone:PhoneApplicationPage 
x:Class="Bank.MainPage" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" 
xmlns:my="clr-namespace:WPCordovaClassLib;assembly=WPCordovaClassLib" 
FontFamily="{StaticResource PhoneFontFamilyNormal}" 
FontSize="{StaticResource PhoneFontSizeNormal}" 
Foreground="{StaticResource PhoneForegroundBrush}" 
SupportedOrientations="Portrait" Orientation="Portrait" 
shell:SystemTray.IsVisible="false"> 
<!--LayoutRoot is the root grid where all page content is placed--> 
    <Grid x:Name="LayoutRoot" Background="Transparent"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="*"/> 
     </Grid.RowDefinitions>   
    <Image x:Name="splashImage" HorizontalAlignment="Center" VerticalAlignment="Center" Source="SplashScreen.png" ImageOpened="OnImageOpened" Opacity="1"></Image> 
     <my:CordovaView HorizontalAlignment="Stretch" 
       Margin="0,0,0,0" 
       x:Name="CordovaView" 
       VerticalAlignment="Stretch" StartPageUri="/www/default/index.html" VerticalContentAlignment="Center"/> 

    <Canvas Name="canvasBrush" Width="640" Height="480" 
       HorizontalAlignment="Left" > 
     <!--Camera viewfinder --> 
     <Canvas.Background> 
      <VideoBrush x:Name="cameraBrush" SourceName="cam"/> 
     </Canvas.Background> 
     </Canvas> 
</Grid>  

的Windows Phone C来自不同的类文件#的SetSource的VideoBrush炫魅广东

我想从appdataInterface.cs的SetSource到的VideoBrush和代码如下

public class cameraCustom : BaseCommand 
{ 
    public void camera(string arg) 
    { 
     PhotoCamera cam; 
     if ((PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true) || 
       (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing) == true)) 
     { 
      // Initialize the camera, when available. 
      if (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing)) 
      { 
       // Use front-facing camera if available. 
       cam = new Microsoft.Devices.PhotoCamera(CameraType.FrontFacing); 
      } 
      else 
      { 
       // Otherwise, use standard camera on back of phone. 
       cam = new Microsoft.Devices.PhotoCamera(CameraType.Primary); 
      } 

      // Event is fired when the PhotoCamera object has been initialized. 
      cam.Initialized += new EventHandler<Microsoft.Devices.CameraOperationCompletedEventArgs>(cam_Initialized); 

      // Event is fired when the capture sequence is complete. 
      cam.CaptureCompleted += new EventHandler<CameraOperationCompletedEventArgs>(cam_CaptureCompleted); 

      // Event is fired when the capture sequence is complete and an image is available. 
      cam.CaptureImageAvailable += new EventHandler<Microsoft.Devices.ContentReadyEventArgs>(cam_CaptureImageAvailable); 

      // Event is fired when the capture sequence is complete and a thumbnail image is available. 
      cam.CaptureThumbnailAvailable += new EventHandler<ContentReadyEventArgs>(cam_CaptureThumbnailAvailable); 

      //Set the VideoBrush source to the camera. 
      Bank.MainPage view = new Bank.MainPage(); 

      view.LayoutRoot.FindName("cameraBrush"); 
     } 
    } 
} 

我想套装

cameraBrush.SetSource(cam); 

from appdataInterface.cs。 我应该怎么做?

回答

0

那么,你不应该那么容易。 通MainPageappdataInterface.cs,然后你可以调用一个方法上MainPage实际上将设置画笔:

// MainPage.xaml.cs 
public void SetBrush(VideoBrush brush) 
{ 
    cameraBrush = brush; 
} 


// appdataInterface.cs 
public appdataInterface(MainPage page) 
{ 
    _page = page; 
} 

// later on 
_page.SetBrush(videoBrush); 
0

如果你会找你的MainPage实例传递给你想要的它应该工作的appdataInterface.cs。

当初始化类,是这样的:

appdataInterface AI =新appdataInterface(); AI.Main = this;

在appdataInterface.cs你应该有:

市民主要的MainPage {获得;设置;}

而且在MainPage.xaml.cs中你应该有cameraBrush - 作为全球公共产品,那么你就可以从你的课上做这个:

Main.cameraBrush.SetSource(cam);