开发者

Is it possible to access an external class' member variable in page.xaml.cs?

开发者 https://www.devze.com 2023-01-30 11:39 出处:网络
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 i

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">
        开发者_C百科        <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 :)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消