I am receiving the error ‘Cannot implicititly convert type ‘System.Windows.Forms.DialogResult’ to System.Windows.MessageBoxResult’
At first I thought this was just a missing import so I put imported System.Windows.Forms but it came to no avail as doing this throws up an error on my actual message box which is ‘MessageBox’ is an ambigous reference between ‘System.Windows.MessageBox’ and ‘System.Windows.Forms.MessageBox’ (Which isn’t to hard to figure out :P) but the original message remains the same.
private void DisplayOnWebsiteChecked(Object sender, EventArgs e)
{
var departments = model.Name;
var departmentChildren = model.Children;
var messagebox = MessageBox.Show("Do you wish to hide all sub deparments and products.",
"List of Box",
MessageBoxButton.YesNo);
if (messagebox = System.Windows.Forms.DialogResult.Yes)
{
if (departmentChildren != null)
{
int zeroChildren = 0;
if (departmentChildren.Count.Equals(zeroChildren)) ;
{
foreach (Department Children in departmentChildren)
Children.IsVisibleOnWebsite = false;
}
}
}
else
return;
}
I have included the whole method just incase you need anything from it.
Given that you’ve now explained that this is a WPF app, if you’re using
System.Windows.MessageBox.Showyou should be comparing againstSystem.Windows.MessageBoxResult.Basically, if you’re doing WPF you almost certainly don’t want any mention of
System.Windows.Forms, and vice versa. (I’m surprised this was compiling at all – do you have references to both assemblies? That’s generally a bad idea…)Additionally, you need to use
==for comparisons, not=(assignment)