<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>
我想从 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);
来自 appdataInterface.cs 。 我该怎么做?
答案 0 :(得分:0)
嗯,你不应该那么容易。
将MainPage
传递给appdataInterface.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);
答案 1 :(得分:0)
如果您将您的MainPage实例传递给appdataInterface.cs,它应该可以正常工作。
初始化课程时,例如:
appdataInterface AI = new appdataInterface(); AI.Main =此;
在appdataInterface.cs中你应该:
public MainPage Main {get; set;}
在MainPage.xaml.cs上你应该有cameraBrush - 作为全球公众,你可以从你的课程中做到这一点:
Main.cameraBrush.SetSource(凸轮);