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
JWoord2y 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
More Posts
Error with app send emailThe goal is to make a send emails app from c# , later on to also send with attachments but im stuck ❔ Can someone help me with my snake game?Hi everyone reading this. I’m pretty new to C#, so please go easy on me. I have a snake-game (wpf)✅ ConsoleApp - run the .exe by cmd and catch given parametersWell, as a little task I'm trying to code a ConsoleApp that should base64 encrypt an input string ~~❔ Bad IL Format Exception when porting .NET Framework 4.8 Project to .NET Core 6.0Hi, I've currently got the glorious task to port a .NET Framework 4.8 project to .NET Core 6.0. So f❔ "Cannot assign requested address [::1]:27017" when connecting to MongoDB on Docker.I have a Docker Compose file with containers - `backend`: ASP.NET Core web API - `mongo`: MongoDB wh❔ External Login Callback (Facebook works, Google doesn't)This is copied from a youtube tutorial and I've been trying to step through and figure out the probl❔ Need someone who is an expert at rating resumes, would really appreciate itMy resume https://cdn.discordapp.com/attachments/684475244664193242/1065827594806763580/Yehor-Belenk❔ Handling different version changes for external standard.Hey! I'm developing tools for a community to support OpenDRIVE standard. The name of the standard do❔ IMAP vs POP3 for getting attachments from an emailI'm building a console app in C# using MailKit to find and save all of the attachments in my outlook❔ WPF MVVM ModelViews and ViewsI have recently learned that ModelView can't have UI elements in it (bad practice). Hence, couple of