SORU
19 Kasım 2008, ÇARŞAMBA


WPF Kullanıcı Denetimi Üst

Ben zamanında bir kullanıcı bir ana pencere içine benim yük var kontrol edin. Yapamam kullanıcının bulunduğu pencere üzerinde kontrolü ele almak.

Bunu denedim.Üst, ama her zaman boş. Herkes bir kullanıcı içeren pencere WPF kontrolü ele almak için nasıl biliyor mu?

Denetimi nasıl yüklenir:

private void XMLLogViewer_MenuItem_Click(object sender, RoutedEventArgs e)
{
    MenuItem application = sender as MenuItem;
    string parameter = application.CommandParameter as string;
    string controlName = parameter;
    if (uxPanel.Children.Count == 0)
    {
    	System.Runtime.Remoting.ObjectHandle instance = Activator.CreateInstance(Assembly.GetExecutingAssembly().FullName, controlName);
    	UserControl control = instance.Unwrap() as UserControl;
    	this.LoadControl(control);
    }
}

private void LoadControl(UserControl control)
{
    if (uxPanel.Children.Count > 0)
    {
    	foreach (UIElement ctrl in uxPanel.Children)
    	{
    		if (ctrl.GetType() != control.GetType())
    		{
    			this.SetControl(control);
    		}
    	}
    }
    else
    {
    	this.SetControl(control);
    }
}

private void SetControl(UserControl control)
{
    control.Width = uxPanel.Width;
    control.Height = uxPanel.Height;
    uxPanel.Children.Add(control);
}

CEVAP
20 Kasım 2008, PERŞEMBE


Aşağıdaki kullanmayı deneyin

Window parentWindow = Window.GetWindow(userControlRefernce);

GetWindow yöntemi sizin için VisualTree yürüyüş ve denetimi barındıran bir pencere bulur.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • BASS212M

    BASS212M

    15 Temmuz 2009
  • jeffisthecoolguy

    jeffisthecoo

    17 HAZİRAN 2013
  • Tome Rodrigo

    Tome Rodrigo

    9 Temmuz 2006