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

  • Home
  • SEARCH
  • 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 8868899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:21:49+00:00 2026-06-14T17:21:49+00:00

I have a command on a ViewModel which I use to navigate to a

  • 0

I have a command on a ViewModel which I use to navigate to a details page

public class InstalledMetersListViewModel : MvxViewModel
    , IMvxServiceConsumer<IInstallMeterRepository>
{
    public List<InstalledMeterListItemViewModel> List { get; set; } 

    public InstalledMetersListViewModel()
    {
        List = new List<InstalledMeterListItemViewModel>();
        foreach (var meter in this.GetService<IInstallMeterRepository>().GetInstalledMeters())
        {
            List.Add(new InstalledMeterListItemViewModel { Serial = meter.Serial, Description = meter.Description });
        }
    }

    public IMvxCommand ShowDetailsCommand
    {
        get
        {
            return new MvxRelayCommand<InstalledMeterListItemViewModel>(type => RequestNavigate<InstalledMeterListItemViewModel>(new {serial = type.Serial.ToString()}));
        }
    }
}

with this View

<ListBox ItemsSource="{Binding List}" x:Name="TheListBox">
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
        </Style>
    </ListBox.ItemContainerStyle>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Border BorderThickness="5,5,5,5" BorderBrush="White">
                <Grid Width="auto" HorizontalAlignment="Stretch" >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="1*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>

                    <TextBlock Text="S/N"/>
                    <TextBlock Text=" : " Grid.Column="1"/>
                    <TextBlock Text="{Binding Serial}" Grid.Column="2"/>

                    <TextBlock Text="Description" Grid.Row="1"/>
                    <TextBlock Text=" : " Grid.Column="1" Grid.Row="1"/>
                    <TextBlock Text="{Binding Description}" Grid.Column="2" Grid.Row="1"/>

                    <Button Content="Details" Grid.Column="3" Grid.RowSpan="2" Command="{Binding Path=DataContext.ShowDetailsCommand, ElementName=TheListBox}" CommandParameter="{Binding}"/>
                </Grid>
            </Border>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

The ViewModel I am navigating to is

public class InstalledMeterListItemViewModel : MvxViewModel,
    IMvxServiceConsumer<IInstallMeterRepository>
{

    public InstalledMeterListItemViewModel(string serial)
    {
        IInstalledMeter meter = this.GetService<IInstallMeterRepository>().GetMeter(Convert.ToDouble(serial));
        Description = meter.Description;
        Serial = meter.Serial;
    }

    public InstalledMeterListItemViewModel()
    {

    }

Problem accessing object – most likely this is caused by an anonymous object being generated as Internal – please see Anonymous types and Get accessors on WP7.1?

But I dont use any internal classes, so I cant see how I can fix this

  • 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-14T17:21:50+00:00Added an answer on June 14, 2026 at 5:21 pm

    This line:

    return new MvxRelayCommand<InstalledMeterListItemViewModel>(
             vm => RequestNavigate<InstalledMeterListItemViewModel>(
                  new {serial = type.Serial.ToString()}));
    

    creates an instance of an anonymous class

    That anonymous class is generated by the compiler (use a tool like Reflector to see it)

    The compiler generates it as internal

    i.e. the compiler create a class a bit like

     internal class Anonymous_Mangled_Name_1223345tHER
     {
         public string serial { get; set; }
     }
    

    and then rewrites your code as:

    return new MvxRelayCommand<InstalledMeterListItemViewModel>(
             vm => RequestNavigate<InstalledMeterListItemViewModel>(
                  new Anonymous_Mangled_Name_1223345tHER
                  {
                      serial = type.Serial.ToString()
                  }));
    

    In order to reflect and use this class, the code in Cirrious.MvvmCross needs to get access to it…

    That’s why you need InternalsVisibleTo – http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx

    See the last line of Conference-AssemblyInfo.cs for an example of the line to add.

    [assembly: InternalsVisibleTo("Cirrious.MvvmCross")]
    

    Note: for the old ‘master’ branch, this is:

    [assembly: InternalsVisibleTo("Cirrious.MvvmCross.WindowsPhone")] 
    // should really also add Cirrious.MvvmCross.Touch - but mono runtime doesn't care 
    // should really also add Cirrious.MvvmCross.Droid - but mono runtime doesn't care 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Silverlight 4 application which has a leaky ViewModel class. I have
I have a ViewModel class which i want to respond to the built in
I'm using M-V-VM and have a command on my ViewModel called 'EntitySelectedCommand'. I've trying
.Net 4 WPF DataGrid MVVM User clicks add button which triggers command on viewmodel.
(Note: I chose to not use the Navigation Framework) I have a WizardViewModel which
I'm making use of the MVVM Light ViewModelLocator. I have a class called GlobalViewModelLocator
I have a ViewModel called CompanyListViewModel . It represents a list of companies in
For security reasons (I'm a developer) I do not have command line access to
I have next command in my batch script dir project\*.java /s /B > temp_file
I have this command to go to every directory and once there run some

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.