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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:14:45+00:00 2026-05-30T07:14:45+00:00

I have a MVVM setup that creates a View on my MainWindow. I am

  • 0

I have a MVVM setup that creates a View on my MainWindow. I am not sure how to know when a user Clicks on a specific Notification Item inside the View. Where would I add the event, or a command to know when that happens?

here are is my MVVM code :

MainWindow

cs:

NotificationViewModel notificationViewModel = new NotificationViewModel();
notificationViewModel.AddNoticiation(new NotificationModel() { Message = "Error", Name = "Station 21" });
NotificationView.DataContext = notificationViewModel;

xaml:

<notification:NotificationView x:Name="NotificationView" />

NotificationModel

public class NotificationModel : INotifyPropertyChanged
{

    private string _Message;
    public string Message
    {
        get { return _Message; }
        set
        {
            if (_Message != value)
            {
                _Message = value;
                RaisePropertyChanged("Message");
            }
        }
    }

    private string _Name;
    public string Name
    {
        get { return _Name; }
        set
        {
            if (_Name != value)
            {
                _Name = value;
                RaisePropertyChanged("Name");
            }
        }
    }

    public string TimeStamp
    {
        get { return DateTime.Now.ToString("h:mm:ss"); }
    }

    #region PropertChanged Block
    public event PropertyChangedEventHandler PropertyChanged;

    private void RaisePropertyChanged(string property)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(property));
        }
    }
    #endregion
}

NotificationViewModel

public class NotificationViewModel 
{
    private ObservableCollection<NotificationModel> _Notifications = new ObservableCollection<NotificationModel>();
    public ObservableCollection<NotificationModel> Notifications 
    { 
        get { return _Notifications; } 
        set { _Notifications = value; } 
    }

    public void AddNoticiation(NotificationModel notification)
    {
        this.Notifications.Insert(0, notification);
    }
}

NotificationView

<Grid>
    <StackPanel HorizontalAlignment="Left" >
        <ItemsControl ItemsSource="{Binding Path=Notifications}"
                      Padding="5,5,5,5">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Border Background="SlateGray"
                            CornerRadius="4">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="100" />
                                <ColumnDefinition Width="100" />
                                <ColumnDefinition Width="100" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0" 
                                       Text="{Binding Path=TimeStamp}" />
                            <TextBlock Grid.Column="1" 
                                       Text="{Binding Path=Name}" />
                            <TextBlock Grid.Column="2" 
                                       Text="{Binding Path=Message}" />
                        </Grid>
                    </Border>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </StackPanel>
</Grid>
  • 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-30T07:14:47+00:00Added an answer on May 30, 2026 at 7:14 am

    There’s no real selection mechanism built into an ItemsControl. It would probably solve your problem to switch out your ItemsControl for a ListBox.

    If you do that, you can bind to SelectedItem, then handle any changes made to SelectedItem using the PropertyChanged event.

    Example:

    In your view model’s constructor:

    PropertyChanged += NotificationViewModel_PropertyChanged;
    

    Add a property to your view model to allow the binding:

    private string _selectedNotification;
    public string SelectedNotification
    {
        get { return _selectedNotification; }
        set
        {
            if (_selectedNotification != value)
            {
                _selectedNotification = value;
                RaisePropertyChanged("SelectedNotification");
            }
        }
    }
    

    Finally, add the event handler to your view model:

    NotificationViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e))
    {
        if (e.PropertyName = "SelectedNotification") DoStuff();
    }
    

    You may find that you don’t even need to hook into PropertyChanged if you just want to update another control in your view based on the selected item in your list box. You can just bind directly to the property within xaml.

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

Sidebar

Related Questions

I have an MVVM setup with a mainwindow that contains a ContentControl. I set
I have a typical MVVM setup of Listbox and vm + DataTemplate and item
I have a MVVM application that has a slider bar and when the user
I have a mvvm(model view viewmodel) silverlight application that has several views that need
I have a WPF/MVVM (using MVVM-Light) app setup with a ComboBox that is inside
i have a mvvm app that the main window is a tab control. i
I have read the MSDN article on MVVM and I am not really convinced.
I have a WPF app that is using the MVVM pattern. Hooking up buttons
I have an MVVM Silverlight 4 application that holds a list of modules (a
Here's the scenario: I have the following user control, the idea is that it's

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.