tags:

views:

47

answers:

2

We have some code that we tried out on a WPF project in .net 4.0 and it worked with using Windows but we re started the project to combine everything together and now we have started to take advantage of the UserControls. My Window that worked with my previous code doesn't work with this new UserControl code and it says what I posted in the title.

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;


namespace WpfPrototype1Screens
{
 /// <summary>
 /// Interaction logic for Screen_1.xaml
 /// </summary>
 public partial class Screen_1 : UserControl
 {

  public Screen_1()
  {
   this.InitializeComponent();


  }

  protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
  {
   base.OnMouseDoubleClick(e);
   FrameworkElement element = e.OriginalSource as FrameworkElement;
   if(element.DataContext is DateTime){
    DateTime date = (DateTime) element.DataContext;
    WpfPrototype1Screens.Add_Event addEvent = new Add_Event(date);
    addEvent.Show();
    addEvent.Focus();
   }
  }
 }
}

The problem comes in the last 2 lines of the OnMouseDoubleClick event method. Focus shows up as fine, but addEvent.Show(); doesn't. It says that there is no such thing as Show() for this type of Usercontrol. Now I have found out that there are different usercontrols... there is the one that I tried to reference by (right clicking --> adding reference --> .Net tab --> and selecting System.Windows.Forms();... but that didn't work because I realized that the UserControl that we are using is not a "forms" usercontrol, it is a Usercontrol control? i guess? I do not know what to do to make this code compile and work

A: 

It's a little difficult to understand the code. It seems that the first part of your code is the user control class, and the second part is the code that needs to use the control. Correct me if I'm wrong.

I think what's going on is you're using the System.Windows.Controls UserControl, which certainly does not have a Show() method. You might be able to use the Visibility property (inherited from UIElement)of the UserControl to show / hide it.

vlad
I tried to change it to Visibility(true); or just Visibility(); and they both just said that they are Non-invocable members 'System.Windows.UiEelemt.Visibility' cannot be used like a method.
Sammy
it's a property, not a method. so if your UserControl is called ABControl, the line should be: 'ABControl.Visibility = true;'
vlad
+1  A: 

Try replacing this part:

WpfPrototype1Screens.Add_Event addEvent = new Add_Event(date);

with either of these:

using WpfPrototype1Screens;

Add_Event addEvent = new Add_Event(date);

Or

WpfPrototype1Screens.Add_Event addEvent = new WpfPrototype1Screens.Add_Event(date);

Hope this helps!

Goblin
Neither one worked and they both still said the same error as an error. Thank you very much for the input though. I appreciate it.
Sammy