是否可以访问外部类? page.xaml.cs中的成员变量?
我正在开发一个 Windows Phone 7 应用程序,并且有两个 xaml 页面。从第一个开始,我嵌入了两个应用程序栏链接来从图库中选择图像或使用相机捕获图像。我希望在第一页上选择的图像显示在第二页上,应用程序栏按钮显示确认是或否。截至目前,我在第一页(barcodeImage)上有一个图像控件,该控件会根据选择进行更新。
MainPage.xaml
<controls:PanoramaItem Header="welcome">
<ScrollViewer Name="sv1" VerticalScrollBarVisibility="Auto">
<StackPanel Height="1100">
<TextBlock TextWrapping="Wrap">Random text here.
</TextBlock>
<Grid x:Name="Grid2" Grid.Row="1" Margin="12,0,12,0">
<Image Height="150" Margin="28,30,168,0" Name="barcodeImage" Stretch="Fill" VerticalAlignment="Top" d:LayoutOverrides="VerticalAlignment" />
</Grid>
</StackPanel>
</ScrollViewer>
</controls:PanoramaItem>
MainPage.xaml.csConfirm.xaml
void cameraCaptureTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
BitmapImage bmp = new BitmapImage();
bmp.SetSource(e.ChosenPhoto);
barcodeImage.Source = bmp;
}
}
我希望
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Image Margin="64,36,57,100" x:Name="barcodeImageFinal" Stretch="Fill" />
</Grid>
barcodeImageFinal 显示最终的位图。我怎样才能做到这一点?感谢您的关注:)
I'm developing a Windows Phone 7 app, and I have two xaml pages. From the first one, I embed two app bar links to select an image from gallery or capture an image using the camera. I would like the image chosen on the first page to be displayed on a second page, with the app bar buttons showing a confirm yes or no. As of now, I have an image control on the first page (barcodeImage) that gets updated with the choice.
MainPage.xaml
<controls:PanoramaItem Header="welcome">
<ScrollViewer Name="sv1" VerticalScrollBarVisibility="Auto">
<StackPanel Height="1100">
<TextBlock TextWrapping="Wrap">Random text here.
</TextBlock>
<Grid x:Name="Grid2" Grid.Row="1" Margin="12,0,12,0">
<Image Height="150" Margin="28,30,168,0" Name="barcodeImage" Stretch="Fill" VerticalAlignment="Top" d:LayoutOverrides="VerticalAlignment" />
</Grid>
</StackPanel>
</ScrollViewer>
</controls:PanoramaItem>
MainPage.xaml.cs
void cameraCaptureTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
BitmapImage bmp = new BitmapImage();
bmp.SetSource(e.ChosenPhoto);
barcodeImage.Source = bmp;
}
}
Confirm.xaml
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Image Margin="64,36,57,100" x:Name="barcodeImageFinal" Stretch="Fill" />
</Grid>
I'd like barcodeImageFinal to display the final bitmap. How can I make this work? Thanks for looking :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我了解您的问题,您希望在
MainPage
的成员中创建一个位图,然后从Confirm
访问它。一种方法是为位图创建某个类的公共静态属性。例如,可以在您的App
中创建public static BitmapImage FinalBitmap
。然后,您可以在cameraCaptureTask_Completed
中设置该属性的值,然后在Confirm
类中创建一个Loaded
处理程序,将图像源设置为存储的位图。我认为如果您将成员设置为静态,那么您的问题标题的答案是肯定的,尽管另一个类并不是真正的“外部”。普通的类成员将无法访问,因为您没有该类的实例。
As I understand your question, you want to create a bitmap in a member of
MainPage
and then access it fromConfirm
. One approach would be to create a public static property of some class for your bitmap. For example, maybe createpublic static BitmapImage FinalBitmap
in yourApp
. Then you could set the value of the property in yourcameraCaptureTask_Completed
and then create aLoaded
handler in yourConfirm
class that sets image source to the stored bitmap.I think the answer to your question title is yes if you make the member static, although the other class isn't really "external". A normal class member won't be accessible because you don't have an instance of that class.