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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:55:50+00:00 2026-06-12T13:55:50+00:00

I Pass an object OptionSelector to a different ViewModel. When passing it is not

  • 0

I Pass an object OptionSelector to a different ViewModel. When passing it is not null. But on the receiving end it shows as null. Any ideas


My View is wrapped in this class.

 public class CoreView : XboxApplicationPage, IRefAppNavigationItem
 {
/// <summary>
        /// Gets or sets navigation data for nested views.
        /// </summary>
        public object Data
        {
            get { return GetValue(DataProperty) as object; }
            set { SetValue(DataProperty, value); }
        }

        /// <summary>
        /// Identifies the Data dependency property.
       /// </summary>
       public static readonly DependencyProperty DataProperty =
         DependencyProperty.Register("Data",typeof(object),typeof(CoreView),new                    PropertyMetadata(null));

        /// <summary>
        /// Gets or sets the viewModel used in this page.
        /// </summary>   
        public CoreViewModel ViewModel
        {
          get 
          { 
              return (CoreViewModel)GetValue(ViewModelProperty); 
          }
          set { SetValue(ViewModelProperty, value); }
        }

         /// <summary>
        /// Sets the View.DataContext to the View.ViewModel. 
        /// </summary>
        private void SetViewModel()
        {
            if (ViewModel != null)
            {
                try
                {
                    if (this.Data != null)
                    {
                        ViewModel.Data = this.Data;
                    }
                    else
                    {     
                        ViewModel.Data = this.Tag;
                    }

                    SetDataContext();
                }
                catch(Exception e)
                {
                    Logger.Log("SetViewModel() error :" + e.StackTrace);
                }
            }
        }
        /// <summary>
        /// Sets the DataContext to the ViewModel. 
        /// Override when additional actions might be required after setting the DataContext. 
        /// </summary>
        protected virtual void SetDataContext()
        {
            this.DataContext = ViewModel;
        }
        /// <summary>
        /// Handles on NavigateTo events.
        /// </summary>
        /// <param name="e">Event args.</param>
        /// <remarks>This method is used to get the post navigation data and integrate into CoreView.</remarks>
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (DesignerProperties.IsInDesignTool)
            {
                return;
            }

            try
            {
                if (this.currentPageCulture != AmebaTV_XBOXApplication.Common.Resources.Localization.CurrentCulture)
                {
                    UpdateLocalizedStrings(this);
                }

                Microsoft.Xbox.Controls.Localization.CultureChanged += Localization_CultureChanged;

                var postNavigationState = IoC.Get<INavigationService>().GetPostNavigationData(NavigationContext);
                if (postNavigationState != null)
                {
                    this.Data = postNavigationState;
                }

                this.ViewModel.OnNavigatedTo();

                if (legendService != null)
                {
                    legendService.IsNavigateBackEnabled = true;
                }
                base.OnNavigatedTo(e);
            }
            catch (Exception ex)
            {
                Logger.Log("OnNavigatedTo : "+ex.Message);
            }


        }

 }

    /// <summary>
    /// Base class for all ViewModels.
    /// </summary>
    public class CoreViewModel : ViewModelBase
    {
         /// <summary>
        /// Field for Data.
        /// </summary>
        private object data;

       /// <summary>
       /// To be used with navigation to populate view models with initial content.
       /// </summary>
       public virtual void OnDataSet()
       {
       }

        /// <summary>
        /// Gets or sets ViewModel data. 
        /// </summary>
        public object Data
        {
            get { return this.data; }
            set
            {
                this.data = value;
                RaisePropertyChanged("Data");
                OnDataSet();
            }
        }
}

OptionSelectorData object

    /// <summary>
    /// Contains data for the options selector view.
    /// </summary>
    public class OptionSelectorData
    {
        /// <summary>
        /// Gets or sets the list of options.
        /// </summary>
        public IList<string> Options { get; set; }

        /// <summary>
        /// Gets or sets the option title.
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// Gets or sets the callback that will be invoked when an option is selected
        /// </summary>
        public Action<string> NotificationCallback { get; set; }
    }
}

Command to trigger navigation

 public class MoreOverflowViewModel : CoreViewModel
 {


        /// <summary>
        /// Navigate to Property filter page
        /// </summary>
        public ICommand gotoViewPagebyCriteria
        {
            get
            {
                return new RelayCommand(() =>
                {
                    OptionSelectorData option = new OptionSelectorData 
                    {
                        Options = filterOptions, Title = 
                        Localization.GetByLocalizationKey("OptionTitleFilter"), 
                        NotificationCallback = OnFilterOptionsCallback 
                    };

                    Messenger.Default.Send(new NavigateToMessage(new 
                    Uri(PageListings.ViewPageByCriteria, UriKind.Relative), option)); 
                });
            }
        }
    }

Viewmodel to receive data, OnDataSet checks object and sets properties

public class ViewByCriteriaViewModel : CoreViewModel
    {
          /// <summary>
        /// ondataset
        /// </summary>
        public override void OnDataSet()
        {
            option = this.Data as OptionSelectorData;
            if (option != null)
            {
                OptionTitle = option.Title;
                itemsSource = option.Options;
            }
            else
            {
                Logger.Log("NULL Option Data");
            }
        }

}

  • 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-12T13:55:52+00:00Added an answer on June 12, 2026 at 1:55 pm

    Its seems I had a default OnNavigatedTo() that was overriding the method in the base class. Issue resolved.

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

Sidebar

Related Questions

I want to pass Object of one activity to another but i am not
I want to pass an object (not just a string or integer) from a
How do you pass an object to a view controller, right before you push
When you pass an object that inherits from MarshalByRefObject to a different AppDomain, won't
Possible Duplicate: How to pass object from one activity to another in Android I
I need to pass Cursor object to another activity, what is the best way
How can I pass an object from a detail disclosure tap to a detail
How can I pass an object of a MyClass (C#) by Parameter-by-Value to a
I need to pass an object (my own business object) between two tables in
I have to pass an object to an button's action... something like [myButton addTarget:self

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.