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 4255532
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:13:54+00:00 2026-05-21T05:13:54+00:00

I’m trying to make a simple Windows Phone 7 Silverlight app. There’s the MainPage.xaml

  • 0

I’m trying to make a simple Windows Phone 7 Silverlight app. There’s the MainPage.xaml with some UI elements, and a separate C# class MyClass.cs with some code.

My problem is: MyClass can’t access anything contained in MainPage (i.e. it doesn’t know the UI elements or C# methods exist).

If I try to inherit MainPage, the app compiles, but refuses to run:

public class MyClass : MainPage
{
   // No good
}

If I try this solution, then I get an InvalidCastException error:

public class MyClass
{
  // Also no good
  MainPage m = (MainPage)Application.Current.RootVisual;
}

My question is: how can I access MainPage from a separate class?

In MainPage.xaml.cs, I can simply use myElement.Property etc. However, this isn’t possible in MyClass, but I’m not sure why.

I guess there’s a simple answer that I’m missing, but I’m really not sure what it is (… C# newbie trying to run before he can walk!?).

Thanks in advance for any advice you can offer.

  • 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-05-21T05:13:55+00:00Added an answer on May 21, 2026 at 5:13 am

    The answer is that you shouldn’t be doing this as this level of coupling is likley to cause issues in the future in terms of reuse and particularly testing.

    You could look at having a separate global view model which has the information (properties) you need and is bound to the view model of the main view.

    If you need your class to call methods on the view then you could look at a messaging system or similar.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I am doing a simple coin flipping experiment for class that involves flipping a
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.