是否可以访问外部类? page.xaml.cs中的成员变量?

发布于 2024-10-07 07:41:43 字数 1582 浏览 2 评论 0原文

我正在开发一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冧九 2024-10-14 07:41:43

据我了解您的问题,您希望在 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 from Confirm. One approach would be to create a public static property of some class for your bitmap. For example, maybe create public static BitmapImage FinalBitmap in your App. Then you could set the value of the property in your cameraCaptureTask_Completed and then create a Loaded handler in your Confirm 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文