© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
4 replies
JWoord

❔ my delegate event is not raising the event

i defined a event in my CustomerViewModel to pass the data to my main viewModel and raise a new event when gets there. i checked internet for a solution for this to gets working but did not find a answer yet

   public partial class CustomerListViewModel : ObservableObject
    {
        public CustomerListViewModel()
        {

customerCollection = new ObservableCollection<Customer>();
Customer jacob = new Customer("Jacob", "Woord", "Urk");


          

customerCollection.Add(jacob);
           


        }

        
       public event Action<Guid> PlaceOrderRequested = delegate { };
        
        [RelayCommand]
        void PlaceOrder(Customer customer)
        {
            PlaceOrderRequested(customer.CustomerId);
        }
   public partial class CustomerListViewModel : ObservableObject
    {
        public CustomerListViewModel()
        {

customerCollection = new ObservableCollection<Customer>();
Customer jacob = new Customer("Jacob", "Woord", "Urk");


          

customerCollection.Add(jacob);
           


        }

        
       public event Action<Guid> PlaceOrderRequested = delegate { };
        
        [RelayCommand]
        void PlaceOrder(Customer customer)
        {
            PlaceOrderRequested(customer.CustomerId);
        }


namespace viewModelBinding
{
    public partial class MainWIndowViewModel : ObservableObject
    {
        //intialize every vieModel
        private CustomerListViewModel customerListViewModel = new CustomerListViewModel();
        
        private OrderListViewModel    orderListViewModel = new OrderListViewModel();
        

        private Timer timer = new Timer(5000);
        public MainWIndowViewModel()
        {
            customerListViewModel.PlaceOrderRequested += CustomerListViewModel_PlaceOrderRequested;
            currentViewModel = new OrderListViewModel();
            timer.Elapsed += (s, e) => NotificationMessage = "Na 5 seconden word de huidige tijd neergzet: " + DateTime.Now.ToLocalTime() + " Kukulukuu";
            timer.Start();
        }

        private void CustomerListViewModel_PlaceOrderRequested(Guid obj)
        {
            orderListViewModel.CustomerId = obj;
            CurrentViewModel = orderListViewModel;
        }

        [ObservableProperty]
        object currentViewModel;

        [ObservableProperty]
        string notificationMessage;

     
namespace viewModelBinding
{
    public partial class MainWIndowViewModel : ObservableObject
    {
        //intialize every vieModel
        private CustomerListViewModel customerListViewModel = new CustomerListViewModel();
        
        private OrderListViewModel    orderListViewModel = new OrderListViewModel();
        

        private Timer timer = new Timer(5000);
        public MainWIndowViewModel()
        {
            customerListViewModel.PlaceOrderRequested += CustomerListViewModel_PlaceOrderRequested;
            currentViewModel = new OrderListViewModel();
            timer.Elapsed += (s, e) => NotificationMessage = "Na 5 seconden word de huidige tijd neergzet: " + DateTime.Now.ToLocalTime() + " Kukulukuu";
            timer.Start();
        }

        private void CustomerListViewModel_PlaceOrderRequested(Guid obj)
        {
            orderListViewModel.CustomerId = obj;
            CurrentViewModel = orderListViewModel;
        }

        [ObservableProperty]
        object currentViewModel;

        [ObservableProperty]
        string notificationMessage;

     
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

✅ Get delegate from event
C#CC# / help
3y ago
Why is the generic delegate does not accept my method?
C#CC# / help
4y ago
✅ delegate and event IMPLEMENTATION question..
C#CC# / help
4y ago
❔ CS0123No overload for 'CanvasMain_PreviewMouseMove' matches delegate for 'EventMouseHandler'
C#CC# / help
3y ago