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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:55:53+00:00 2026-06-13T12:55:53+00:00

I am using MVVM and I have a listview which is binded to a

  • 0

I am using MVVM and I have a listview which is binded to a dictionary in my viewmodel. In my xaml, I’ve set up the selecteditem to set the correct selected item but unfortunately what I’m doing doesnt work. If I change it to selectedindex with the property datatype changed to int, I’m able to set it. Here’s my view.

View(xaml)

<Grid Width="auto" Grid.Column="0" Grid.Row="1" HorizontalAlignment="Left" Margin="0,1,0,0">
    <Grid.RowDefinitions>
        <RowDefinition Height="auto"></RowDefinition>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="188"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <ListView Name="lstNewPatient" HorizontalAlignment="Left" VerticalAlignment="Bottom" 
         Height="auto" Margin="0,0,0,0" ItemsSource="{Binding Path=TestList}" SelectedItem="{Binding Path=SelectedTestItem}" 
         FontSize="11" SelectionMode="Single">
        <ListView.View>
            <GridView>
                <GridView.ColumnHeaderContainerStyle>
                    <Style>
                        <Setter Property="FrameworkElement.Visibility" Value="Collapsed"/>
                    </Style>
                </GridView.ColumnHeaderContainerStyle>
                <GridViewColumn Width="69" DisplayMemberBinding="{Binding Key}"></GridViewColumn>
                <GridViewColumn Width="109" DisplayMemberBinding="{Binding Value}"></GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>
</Grid>

ViewModel

Dictionary<int, string> selectedTestItem= null;
public Dictionary<int, string> SelectedTestItem
{
    get 
    { 
        return selectedTestItem; 
    }
    set
    {
        selectedTestItem = value;
        OnPropertyChanged("SelectedTestItem");
    }
}

private Dictionary<int, string> TestList()
{
    var newTestList = new Dictionary<int, string>();

    newTestList.Add(1, "Apple");
    newTestList.Add(2, "Car");
    newTestList.Add(3, "Laptop");


    return newPtLevelList;
}
  • 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-13T12:55:54+00:00Added an answer on June 13, 2026 at 12:55 pm

    SelectedTestItem should be KeyValuePair<int, string>, not Dictionary<int, string>

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

Sidebar

Related Questions

I have a working WPF app using MVVM pattern in which the ViewModel calls
I am using MVVM pattern and I have one DataGrid with a column which
I'm developing a WPF app using MVVM. Most of my views have only xaml
Using the MVVM pattern creating WPF applications you have the ViewModel providing data to
I am using the MVVM pattern, I have a view which creates a new
I'm using MVVM. I have two listview. The first listview is fine, i'm able
Using MVVM. I have a DataTemplate which I am using to display an expander
I am using Mvvm-Light and have been ignoring how binding in XAML really works
The application I'm currently writing is using MVVM with the ViewModel-first pattern. I have
I'm working on a WPF/XAML app using MVVM and have a collection of strings

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.