Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8955433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:33:16+00:00 2026-06-15T14:33:16+00:00

I was trying to use the MVVM pattern on my first (very simple) WP7

  • 0

I was trying to use the MVVM pattern on my first (very simple) WP7 app but I got seriously stuck and now I am just trying to get it working without caring about MVVM.

I have a MainViewModel for my MainPage, which works fine. I have a button that passes some data and navigates to a “details page.” I had setup a navigation service to navigate to the details page and pass parameters, which works fine. I just couldn’t get the databinding to the view working. Since it is a simple app, I decided I would pass the data from the DetailsPageVieModel.cs to the DetailsPage.xaml.cs code behind and do the work there. Here is what that veiw model portion looks like.

public override void Initialize(IDictionary<string, string> parameters)
{
    DetailsPage dp = new DetailsPage();
    //DetailsPage dp = Application.Current.RootVisual as DetailsPage;
    base.Initialize(parameters);
    parameters.TryGetValue("url", out vidUrl);
    dp.LoadVideoData(vidUrl);
}

In my DetailsPage.xaml.cs I have the following:

    public void LoadVideoData(string url)
    {
        HtmlWeb doc = new HtmlWeb();
        doc.LoadAsync("http://mydomain.com/video.php?url=" + url);
        doc.LoadCompleted += doc_LoadCompleted;
    }

    private void doc_LoadCompleted(object sender, HtmlDocumentLoadCompleted e)
    {
        this.vidTitle.Text = e.Document.GetElementbyId("title").InnerText;
        vidId = e.Document.GetElementbyId("youtubeId").InnerText;
        this.vidUrl.Source = new Uri("http://mydomain.com/video.php?url=" + vidUrl, UriKind.Absolute);

        BitmapImage bi = new BitmapImage();

        using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
        {
            using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("temp.jpg", FileMode.Open, FileAccess.Read))
            {
                bi.SetSource(fileStream);
                this.vidImg.Height = bi.PixelHeight;
                this.vidImg.Width = bi.PixelWidth;
            }
        }
        this.vidImg.Source = bi;
    }

And here is the relevant DetailsPage.xaml code

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <StackPanel>
            <TextBlock x:Name="vidTitle" Canvas.ZIndex="99" />
            <TextBlock Canvas.ZIndex="99" Text="Tap on the image to view the video." FontSize="14" Margin="0"/>
            <Button Margin="0 -50" Padding="0" BorderThickness="0">
                <Image x:Name="vidImg" Height="225" />
            </Button>
            <StackPanel Canvas.ZIndex="99" Height="516">
                <phone:WebBrowser x:Name="vidUrl" IsScriptEnabled="True" Height="516" Margin="0"/>
            </StackPanel>
        </StackPanel>
    </Grid>

I am guessing the problem lies with the following

DetailsPage dp = new DetailsPage();
//DetailsPage dp = Application.Current.RootVisual as DetailsPage;

Neither of these lines of code works. The first line executes properly but the page doesn’t get updated with the proper data. And the second line gives me a runtime error message when it gets to the dp.LoadVideoData(vidUrl); line.

This is my first Windows Phone app and I would appreciate any help anyone can provide.

Kamal

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:33:18+00:00Added an answer on June 15, 2026 at 2:33 pm

    After digging around some more, I found the following solution.

    DetailsPage currentPage = (App.Current as App).RootFrame.Content as DetailsPage;
    

    I put this code in DetailsPageViewModel.cs. But for other newbies like me, there is nothing special about the name of the file. It could have very well been Monkey.cs. The above code just gives you access to the code behind of the current page being displayed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use the MVVM pattern for the first time. So I
I'm trying to use Telerik RadControls in a MVVM kind of way but having
I'm trying to use Prism and the MVVM pattern to develop an application. In
I am trying to use MVVM in Silverlight, but I am quite new to
I am working on an app where I am trying to use MVVM for
I'm trying to use databinding in WPF with an MVVM pattern. So far, it
I use MVVM pattern in my WPF application. I'm trying to cache my windows
I'm trying to use the MVVM pattern in my Silverlight 3 application and am
I'm building a simple data entry app in WPF form using the MVVM pattern.
I'm trying to learn the MVVM software design pattern. I've got Matthew MacDonald's book,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.