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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:55:41+00:00 2026-05-28T01:55:41+00:00

How to bind the custom property to the selected node’s IsSelected property in MVVM,

  • 0

How to bind the custom property to the selected node’s IsSelected property in MVVM,
I have loaded the nodes at runtime into the treeview. I am using MVVM

  • 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-28T01:55:42+00:00Added an answer on May 28, 2026 at 1:55 am

    Here’s a small example:

    public abstract class ViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
    
        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
    
    public class MyViewModel : ViewModel
    {
        public ObservableCollection<Item> Items
        {
            get
            {
                return new ObservableCollection<Item>()
                {
                    new Item() {DisplayValue = "Item1", IsSelected = false, Sample = "Sample: I am Item1"},
                    new Item() {DisplayValue = "Item2", IsSelected = true, Sample = "Sample: I am Item2"},
                    new Item() {DisplayValue = "Item3", IsSelected = false, Sample = "Sample: I am Item3"}
                };
            }
        }
    }
    
    public class Item : ViewModel
    {
        public string DisplayValue { get; set; }
    
        private bool _isSelected = false;
    
        public bool IsSelected
        {
            get
            {
                return _isSelected;
            }
            set
            {
                _isSelected = value;
                OnPropertyChanged("IsSelected");
            }
        }
    
        private string _sample;
    
        public string Sample
        {
            get
            {
                return _sample;
            }
            set
            {
                _sample = value;
                OnPropertyChanged("Sample");
            }
        }
    }
    

    XAML:

    <Window x:Class="WpfApplication93.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:WpfApplication93"
            Title="MainWindow" Height="350" Width="525">
      <Grid>
        <Grid.DataContext>
          <local:MyViewModel></local:MyViewModel>
        </Grid.DataContext>
    
        <StackPanel>
          <TreeView x:Name="myTreeView" ItemsSource="{Binding Items}">
            <TreeView.ItemContainerStyle>
              <Style TargetType="{x:Type TreeViewItem}">
                <Setter Property="IsSelected" Value="{Binding IsSelected}"></Setter>
                <Setter Property="Template">
                  <Setter.Value>
                    <ControlTemplate TargetType="TreeViewItem">
                      <TextBlock Text="{Binding DisplayValue}"></TextBlock>
                    </ControlTemplate>
                  </Setter.Value>
                </Setter>
    
                <Style.Triggers>
                  <Trigger Property="IsSelected" Value="True">
                    <!-- if you want to customize the appearance of a selected element do it here -->
                    <Setter Property="FontWeight" Value="Bold" />
                  </Trigger>
                </Style.Triggers>
              </Style>
            </TreeView.ItemContainerStyle>
          </TreeView>
    
          <Label Content="{Binding ElementName=myTreeView, Path=SelectedItem.Sample}"></Label>
        </StackPanel>
      </Grid>
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom control but I can't bind a property to the
I am trying to implement custom ObservableCollection Which will have current (selected) item property
I have a custom object type dependency property that is being populated at runtime.
I don't understand, I have a toolbar with buttons bind to custom commands. Also
I have a custom ItemTemplate for a ListBox and I need to bind a
I have created a custom collection class that I am trying to bind to
In Xaml I can set a custom attached property using local:TestClass.TestProperty=1 An I can
I'm trying to bind a Label's 'Content' property to a property from some custom
I am trying to bind a property (Button.Background) to a property on my custom
I have the following setup using Core Data: Nib1: A WindowController with two custom

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.