C
C#2y ago
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;


3 Replies
Tvde1
Tvde12y ago
are you sure PlaceOrder() is called anywhere? Urk btw 😂
JWoord
JWoordOP2y ago
y sure the place order is called in my view and its working, it just never gets to the mainVieModel to get raised. Yes im from Urk 🙂
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server