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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:00:46+00:00 2026-06-09T22:00:46+00:00

I have UserControl(AllCustomerView) in project and its Viewmodel as ALlCustomerViewModel consists a property as

  • 0

I have UserControl(AllCustomerView) in project and its Viewmodel as ALlCustomerViewModel consists a property as SearchText.
SearchText is selected value for TextBox inside a listview in UserControl.
SearchItem is set as customerViewmdel for SearchText.
But in listview , SearchItem is not set as selected

in AllCustomerView.xaml

<TextBlock>
<TextBox 
        Width="150" 
        Text="{Binding Path=SearchText, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
</TextBox>
<Button 
         Command="{Binding Path=SearchCommand}"
         Content=" Search ">
</Button>
</TextBlock>

<ListView
            SelectedValue="{Binding Path=SearchText}"
            ItemsSource="{Binding Path=AllCustomers}"
            FontFamily="Tahoma"
            FontSize="14"
            ItemContainerStyle="{StaticResource CustomerItemStyle}" 
            IsSynchronizedWithCurrentItem="True">
            <ListView.View>
                <GridView>
                    <GridViewColumn>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Button 
                                    Command="{Binding ElementName=Root, Path=DataContext.DeleteCommand}"
                                    Content="x"
                                    FontFamily="Tahoma"
                                    FontSize="10"
                                    />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Button 
                                     FontFamily="Tahoma"
                                    FontSize="10"
                                    Content="Edit"
                                    Command="{Binding Path=DataContext.Editcommand,ElementName=Root}"
                                    />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn
                        Header="CustomerID"
                        Width="130"
                        DisplayMemberBinding="{Binding Path=CustomerID}"/>
                    <GridViewColumn
                        Header="Contact Name"
                        Width="130"
                        DisplayMemberBinding="{Binding Path=ContactName}"/>
                    <GridViewColumn
                        Header="Company Name"
                        Width="130"
                        DisplayMemberBinding="{Binding Path=CompanyName}"/>
                    <GridViewColumn
                        Width="130"
                        Header="Contact Name"
                        DisplayMemberBinding="{Binding Path=ContactTitle}"
                        />
                </GridView>
            </ListView.View>
        </ListView>

and its viewmodel(AllcustomerViewModel.cs)

public ICommand SearchCommand
        {
            get
            {
                if (_search == null)
                    _search = new Relaycommand(SearchCustomer);
                return _search;
            }
        }

 public void SearchCustomer(object o)
 {
            System.Windows.Forms.MessageBox.Show(SearchItem.ToString());

}

 public string searchText;
 public string SearchText
 {
     get { return searchText; }
     set 
     {
       searchText = value;
       var customerExsits = AllCustomers.Where(q => q.CustomerID.Trim().Equals(searchText));
        if (customerExsits.Any())
                {
                    SearchItem = customerExsits.Single();
                }

            }
        }

public CustomerViewModel SearchItem
{
            get;
            set;
}

what should i set in SelectedValue in ListView, whether to set Customerviewmodel(as SelectedItem) or to set CustomerID(as SearchText)?

  • 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-09T22:00:47+00:00Added an answer on June 9, 2026 at 10:00 pm

    You should do the following:

    1. Use this binding in your ListView: SelectedItem="{Binding Path=SearchItem }". Don’t use SelectedValue.
    2. Implement INotifyPropertyChanged in your ViewModel and raise the PropertyChanged event in the setter of the SearchItem property. Obviously, you need to change this property from an automatic one to a classical one with a backing field:

      public CustomerViewModel SearchItem
      {
          get { return _searchItem; }
          set
          {
              if(value == _searchItem)
                  return;
              _searchItem = value;
              RaisePropertyChanged("SearchItem");
          }
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a usercontrol with a Tree inside it with, the command property binds
I have a UserControl in my Asp.net project that has a public property. I
I have an UserControl(AutoComplete) with his own ViewModel. When I use the UserControl inside
I have a UserControl which contains a TextBox . When my main window loads
I have a UserControl with a dependency property called ItemsSource . When the property
I have a usercontrol which overrides the property Text. But this property is not
I have a UserControl with the following Property: public List<Rect> HotSpots { get {
I have created Usercontrol called Attach_Template and I assigned its ID as attachTemplate in
I have usercontrol called as 'DateControl1' in which i have textbox and a calenderextender(ajax).I
I have UserControl which contains a TextBox and a Button control. The Button opens

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.