当前位置: 首页>>代码示例>>C#>>正文


C# UserControl.GetType方法代码示例

本文整理汇总了C#中System.Windows.Controls.UserControl.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# UserControl.GetType方法的具体用法?C# UserControl.GetType怎么用?C# UserControl.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.UserControl的用法示例。


在下文中一共展示了UserControl.GetType方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WhenCalledConvert_CreatesNewViewOrReturnsCachedOneIfAny

        public void WhenCalledConvert_CreatesNewViewOrReturnsCachedOneIfAny()
        {
            var converter = new EditorSelector();
            var privateAccessor = new PrivateAccessor(converter);

            EditorSelector.ResetComposedConverter();

            var view = new UserControl();
            const string fieldType = "testFieldType";

            converter.EditorFactories = new[]
                                            {
                                                new ExportFactory<UserControl, IExportAsControlForTypeMetadata>(
                                                    () => new Tuple<UserControl, Action>(view, () => { }),
                                                    new ExportAsControlForTypeAttribute(fieldType))
                                            };

            var fieldItemMock = Mock.Create<IFieldItem>(Behavior.CallOriginal);

            Mock.Arrange(() => fieldItemMock.FieldType).Returns(fieldType);
            Mock.Arrange(() => fieldItemMock.CanEdit).Returns(true);
            Mock.Arrange(() => fieldItemMock.CanView()).Returns(true);
            Mock.Arrange(() => fieldItemMock.IsInformationOnly).Returns(false);

            var returnedView = (UserControl)converter.Convert(fieldItemMock, new TypeDelegator(typeof (object)), new object(), null);

            Assert.AreEqual(view.GetType(), returnedView.GetType());
            Assert.AreSame(fieldItemMock, returnedView.DataContext);
            Assert.IsTrue(returnedView.IsEnabled);

            //check that view was cached in RegisteredViews table
            UserControl cachedView;
            var registeredViews = privateAccessor.GetField("RegisteredViews") as ConditionalWeakTable<IFieldItem, UserControl>;
            Assert.IsNotNull(registeredViews);
            Assert.IsTrue(registeredViews.TryGetValue(fieldItemMock, out cachedView));

            //remove cached view to ensure that converter will create a new one
            registeredViews.Remove(fieldItemMock);

            Mock.Arrange(() => fieldItemMock.CanEdit).Returns(false);
            Mock.Arrange(() => fieldItemMock.CanView()).Returns(false);

            returnedView = (UserControl)converter.Convert(fieldItemMock, new TypeDelegator(typeof(object)), new object(), null);

            Assert.AreEqual(view.GetType(), returnedView.GetType());
            Assert.AreSame(fieldItemMock, returnedView.DataContext);
            Assert.IsFalse(returnedView.IsEnabled);

            //now converter should return the cached view
            Mock.Arrange(() => fieldItemMock.CanEdit).Returns(true);
            Mock.Arrange(() => fieldItemMock.CanView()).Returns(true);

            var returnedCachedView = (UserControl)converter.Convert(fieldItemMock, new TypeDelegator(typeof(object)), new object(), null);

            Assert.IsTrue(ReferenceEquals(returnedView, returnedCachedView));
            Assert.AreSame(fieldItemMock, returnedCachedView.DataContext);
            Assert.IsFalse(returnedCachedView.IsEnabled);
        }
开发者ID:mparsin,项目名称:Elements,代码行数:58,代码来源:EditorSelectorTest.cs

示例2: ChangeScreen

        public void ChangeScreen(UserControl screen)
        {
            //foreach (var element in MainDock.Children)
            //{
            //    if (element.GetType().Name == "LoadingScreen")
            //    {
            //        MainDock.Children.Remove((UIElement) element);
            //    }
            //}

            if (screen.GetType().Name == "RemoteControlScreen")
            {
                OnRemoteCategory();
            }
            else
            {
                OnStoreCategory();
            }
            var lastElement = MainDock.Children[MainDock.Children.Count - 1];
            //if (lastElement.GetType() == screen.GetType())
            //{
            //    return;
            //}
            MainDock.Children.Remove(lastElement);
            MainDock.Children.Add(screen);

            //GC.Collect();
            //GC.WaitForPendingFinalizers();
        }
开发者ID:huucp,项目名称:tuneRobo,代码行数:29,代码来源:MainWindow.xaml.cs

示例3: registerUserController

 public static void registerUserController(UserControl controller, string name)
 {
     if (pages.Keys.Contains(name))
     {
         throw new ArgumentException("PageName [" + name + "] is already registered!");
     }
     if (pages.Values.Contains(controller))
     {
         throw new ArgumentException("UserControl [" + controller + "] is already registered!");
     }
     pages.Add(name, controller);
     pagec.Add(controller.GetType(), controller);
 }
开发者ID:Ch4s3r,项目名称:Wildstar_Bot,代码行数:13,代码来源:PageController.cs

示例4: OpenWindow

        public void OpenWindow(UserControl userControl)
        {
            var window = _package.FindToolWindow(typeof(BaseToolWindow),
                                                      Math.Abs(userControl.GetType().ToString().GetHashCode()),
                                                      true);

            if (window == null || window.Frame == null)
            {
                throw new NotSupportedException(Resources.CanNotCreateWindow);
            }

            ((BaseToolWindow)window).SetContent(userControl);

            var windowFrame = (IVsWindowFrame)window.Frame;

            VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
        }
开发者ID:zhongleiyang,项目名称:vstalk,代码行数:17,代码来源:WindowsManager.cs

示例5: CreateViewModel

        /// <summary>
        /// Creates a view model for the specified view. This uses the view model type
        /// specified using a ViewModelAttribute if one is specified, and falls back to
        /// convention.
        /// The convention locates a type in the same namespace/assembly as the view, with
        /// a type name formed by adding the 'Model' or 'ViewModel' suffix to the view's type name.
        /// </summary>
        /// <param name="userControl">The control for which the view model must be created.</param>
        /// <returns>The view model instance if one could be located and instantiated.</returns>
        public static object CreateViewModel(UserControl userControl)
        {
            if (userControl == null) {
                throw new ArgumentNullException("userControl");
            }

            Type viewType = userControl.GetType();
            Type viewModelType = null;

            ViewModelAttribute vmAttribute =
                viewType.GetCustomAttributes(typeof(ViewModelAttribute), /* inherit */ true).
                         OfType<ViewModelAttribute>().FirstOrDefault();
            if (vmAttribute != null) {
                viewModelType = vmAttribute.ViewModelType;
            }

            if (viewModelType == null) {
                string viewModelTypeName = viewType.FullName + "Model";
                viewModelType = viewType.Assembly.GetType(viewModelTypeName, /* throwOnError */ false);

                if ((viewModelType == null) &&
                    (viewType.Name.EndsWith("View", StringComparison.Ordinal) == false)) {
                    viewModelTypeName = viewType.FullName + "ViewModel";
                    viewModelType = viewType.Assembly.GetType(viewModelTypeName, /* throwOnError */ false);
                }
            }

            if (viewModelType != null) {
                if (ComponentContainer.Global != null) {
                    return ComponentContainer.Global.GetObject(viewModelType);
                }

                return Activator.CreateInstance(viewModelType);
            }

            return null;
        }
开发者ID:nikhilk,项目名称:silverlightfx,代码行数:46,代码来源:ViewModelAttribute.cs

示例6: ToastHelper

		public ToastHelper(UserControl control)
		{
			_window = new ToastWindow(control);
			ToastType = control.GetType();
		}
开发者ID:irufus,项目名称:Hearthstone-Deck-Tracker,代码行数:5,代码来源:ToastHelper.cs

示例7: navigate

 public void navigate(UserControl fromView, UserControl destView)
 {
     ViewStack.Add((UserControl)fromView);
     View.MainWindow mainwindow = (View.MainWindow)Application.Current.MainWindow;
     string destType = destView.GetType().Name;
     if (destType == "Patients")
         mainwindow.patient_nav_item.Style = (Style)Application.Current.FindResource("ActiveMenuButton");
     else
         mainwindow.patient_nav_item.Style = (Style)Application.Current.FindResource("MenuButton");
     if (destType == "Personnel")
         mainwindow.personnel_nav_item.Style = (Style)Application.Current.FindResource("ActiveMenuButton");
     else
         mainwindow.personnel_nav_item.Style = (Style)Application.Current.FindResource("MenuButton");
     FadeOut = true;
     mainwindow.contentcontrol.Content = destView;
     FadeOut = false;
 }
开发者ID:yoan-durand,项目名称:MTIHospital,代码行数:17,代码来源:MainWindow.cs

示例8: CreateTabItem

        public void CreateTabItem(UserControl userControl, string tabName, bool singleInstance = false,  Visibility closeButtonVisibility = Visibility.Visible,bool apendThisTabItem = true)
        {
            if (singleInstance)
            {
                if (SingleInstanceCompare == SingleInstanceCompareOption.HeaderCompare)
                {
                    string item = _tabItemRegisterList.Where(c => c == tabName).FirstOrDefault();
                    if (item == null)
                        _tabItemRegisterList.Add(tabName);
                    else
                    {
                        foreach (CloseableTabItem ti in TabControl1.Items)
                        {
                            var c = ti.Content as TabAppFormChild;
                            if (c.TitleLabel.Content.ToString() == tabName)
                            {
                                ti.IsSelected = true;
                                return;
                            }
                        }
                    }
                }
                else
                {
                    string item = _tabItemRegisterList.Where(c => c == userControl.GetType().Name).FirstOrDefault();
                    if (item == null)
                        _tabItemRegisterList.Add(userControl.GetType().Name);
                    else
                    {
                        foreach (CloseableTabItem ti in TabControl1.Items)
                        {
                            var c = ti.Content as TabAppFormChild;
                            if (c.UserControl1.Content.GetType().Name == userControl.GetType().Name)
                            {
                                ti.IsSelected = true;
                                return;
                            }
                        }
                    }
                }

            }

            var child = new TabAppFormChild();
            child.UserControl1.Content = userControl;
            child.TitleLabel.Content = tabName;

            var tabItem = new CloseableTabItem();
            tabItem.CloseButtonVisibility = closeButtonVisibility;

            var tb = new TextBlock();
            tb.Text = tabName.Length > 25 ? tabName.Substring(0, 25) + ".." : tabName;

            tb.TextTrimming = TextTrimming.CharacterEllipsis;
            tb.TextWrapping = TextWrapping.NoWrap;

            tabItem.Header = tb;
            tabItem.Content = child;
            if (apendThisTabItem)
                TabControl1.Items.Add(tabItem);
            else
                TabControl1.Items.Insert(0, tabItem);
            tabItem.IsSelected = true;
        }
开发者ID:jerry27syd,项目名称:WPFs,代码行数:64,代码来源:TabAppForm.xaml.cs

示例9: ReLoadColumnComboBox

        private void ReLoadColumnComboBox(UserControl uc)
        {
            string controlType = uc.GetType().ToString();

            switch (controlType)
            {
                case "FastDB.Control.WhereTabRegularConditionControl":
                    WhereTabRegularConditionControl wsToCheck = (WhereTabRegularConditionControl)uc;
                    wsToCheck.cmbWhereTabLeftSideColumns.ItemsSource = GetColumnsFromAllFromTabTable();
                    wsToCheck.cmbWhereTabRightSideColumns.ItemsSource = wsToCheck.cmbWhereTabLeftSideColumns.ItemsSource;
                    break;
                case "FastDB.Control.WhereTabBetweenConditionControl":
                    WhereTabBetweenConditionControl wsbToCheck = (WhereTabBetweenConditionControl)uc;
                    wsbToCheck.cmbWhereTabBetweenColumns.ItemsSource = GetColumnsFromAllFromTabTable();
                    break;
                case "FastDB.Control.WhereTabInNotInConditionControl":
                    WhereTabInNotInConditionControl wInNotIn = (WhereTabInNotInConditionControl)uc;
                    wInNotIn.cmbWhereTabInNotInColumns.ItemsSource = GetColumnsFromAllFromTabTable();
                    break;
                case "FastDB.Control.WhereTabNullNotNullConditionControl":
                    WhereTabNullNotNullConditionControl wNullNotNull = (WhereTabNullNotNullConditionControl)uc;
                    wNullNotNull.cmbWhereTabNullNotNullColumns.ItemsSource = GetColumnsFromAllFromTabTable();
                    break;
            }
        }
开发者ID:mukeshdepani,项目名称:ParaRD,代码行数:25,代码来源:WhereTabControl.xaml.cs

示例10: GoTo

 public void GoTo(UserControl control)
 {
     Placeholder.Content = control;
     Context.Get<IGA>().TrackPageViewAsync(control.GetType().Name);
 }
开发者ID:rburda82,项目名称:proxysearcher,代码行数:5,代码来源:ControlNavigator.cs

示例11: LoadControl


//.........这里部分代码省略.........
                    {
                        NavigationImage navImageControl = new NavigationImage(obj.Property("Screen").Value, obj);
                        navImageControl.MouseLeftButtonUp += new MouseButtonEventHandler(Navigaton_Image_MouseLeftButtonUp);
                        navImageControl.MouseRightButtonDown += new MouseButtonEventHandler(Navigaton_Image_MouseRightButtonDown);
                        canGUI.Children.Add(navImageControl);
                        double dX = Convert.ToDouble(obj.Property("X").Value);
                        double dY = Convert.ToDouble(obj.Property("Y").Value);
                        int dZ = Convert.ToInt32(obj.Property("ZOrder").Value);
                        Canvas.SetLeft(navImageControl, dX * gWidthRatio);
                        Canvas.SetTop(navImageControl, dY * gHeightRatio);
                        Canvas.SetZIndex(navImageControl, dZ);
                        navImageControl.Location.X = dX;
                        navImageControl.Location.Y = dY;
                        navImageControl.Width = navImageControl.ImageWidth * gWidthRatio;
                        navImageControl.Height = navImageControl.ImageHeight * gHeightRatio;
                        navImages.Add(navImageControl);
                        controlTypes.Add(typeof(NavigationImage));
                        navImageControl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (MySqlException myerror)
                    { MessageBox.Show("GUI Error Load Navigation Image: " + myerror.Message); }
                }
                else if (obj.Type == "CONTROL CAMERA VIEWER")
                {
                    try
                    {
                        string stream = OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Property("Object Name").Value, "Stream Address").Value;
                        VideoStreamViewer vsv = new VideoStreamViewer(stream, obj, gAppName);
                        vsv.MouseRightButtonDown += new MouseButtonEventHandler(VideoStreamViewer_MouseRightButtonDown);
                        canGUI.Children.Add(vsv);
                        double dX = Convert.ToDouble(obj.Property("X").Value);
                        double dY = Convert.ToDouble(obj.Property("Y").Value);
                        int dZ = Convert.ToInt32(obj.Property("ZOrder").Value);
                        Canvas.SetLeft(vsv, dX * gWidthRatio);
                        Canvas.SetTop(vsv, dY * gHeightRatio);
                        Canvas.SetZIndex(vsv, dZ);
                        vsv.Location.X = dX;
                        vsv.Location.Y = dY;
                        cameraViewers.Add(vsv);
                        controlTypes.Add(typeof(VideoStreamViewer));
                        vsv.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (MySqlException myerror)
                    { MessageBox.Show("GUI Error Load Camera Viewer: " + myerror.Message); }
                }
                else if (obj.BaseType == "USER CONTROL")
                {
                    string sUCType = obj.Property("Control Type").Value;
                    sUCType = sUCType.Replace("USER CONTROL ", "");
                    OSAE.Types.AvailablePlugin selectedPlugin = GlobalUserControls.OSAEUserControls.AvailablePlugins.Find(sUCType);
                    selectedPlugin.Instance.InitializeMainCtrl(obj, gAppName, gCurrentUser);
                    dynamic uc = new UserControl();
                    uc = selectedPlugin.Instance.mainCtrl;
                    uc.MouseRightButtonDown += new MouseButtonEventHandler(UserControl_MouseRightButtonDown);
                    uc.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    double dX = Convert.ToDouble(obj.Property("X").Value);
                    double dY = Convert.ToDouble(obj.Property("Y").Value);
                    int dZ = Convert.ToInt32(obj.Property("ZOrder").Value);
                    Canvas.SetLeft(uc, dX * gWidthRatio);
                    Canvas.SetTop(uc, dY * gHeightRatio);
                    Canvas.SetZIndex(uc, dZ);
                    uc.setLocation(dX, dY);
                    uc.Width = uc.ControlWidth * gWidthRatio;
                    uc.Height = uc.ControlHeight * gHeightRatio;
                    canGUI.Children.Add(uc);
                    userControls.Add(uc);
                    controlTypes.Add(uc.GetType());
                }
                else if (obj.Type == "CONTROL BROWSER")
                {
                    if (gDebug) Log.Debug("Loading BrowserControl: " + obj.Name);
                    try
                    {
                        OSAE.UI.Controls.BrowserFrame bf = new OSAE.UI.Controls.BrowserFrame(obj);
                        bf.MouseRightButtonDown += new MouseButtonEventHandler(Broswer_Control_MouseRightButtonDown);
                        //OSAE.UI.Controls.StaticLabel sl = new OSAE.UI.Controls.StaticLabel(obj);
                        canGUI.Children.Add(bf);
                        int dZ = Int32.Parse(obj.Property("ZOrder").Value);
                        bf.Location.X = Double.Parse(obj.Property("X").Value);
                        bf.Location.Y = Double.Parse(obj.Property("Y").Value);
                        bf.Width = Double.Parse(obj.Property("Width").Value) * gWidthRatio;
                        bf.Height = Double.Parse(obj.Property("Height").Value) * gHeightRatio;
                        bf.ControlWidth = bf.Width;
                        bf.ControlHeight = bf.Height;
                        Canvas.SetLeft(bf, bf.Location.X * gWidthRatio);
                        Canvas.SetTop(bf, bf.Location.Y * gHeightRatio);
                        Canvas.SetZIndex(bf, dZ);
                        browserFrames.Add(bf);
                        controlTypes.Add(typeof(OSAE.UI.Controls.BrowserFrame));
                        //
                        bf.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Error updating BrowserControl", ex);
                        return;
                    }
                }
            }));
        }
开发者ID:opensourceautomation,项目名称:Open-Source-Automation,代码行数:101,代码来源:MainWindow.xaml.cs

示例12: ExtractName

 private string ExtractName(UserControl control)
 {
     var hostedControlAttr = control.GetType().GetCustomAttributes(true)
         .OfType<HostedControlAttribute>()
         .FirstOrDefault();
     if (hostedControlAttr == null)
     {
         return "Unknown";
     }
     return hostedControlAttr.Name;
 }
开发者ID:zhongleiyang,项目名称:vstalk,代码行数:11,代码来源:BaseToolWindow.cs

示例13: CreateProgramIcon

        void CreateProgramIcon(string url, UserControl programUc, string processName)
        {
            var taskIcon = new Image();
            taskIcon.Source = new BitmapImage(new Uri(url));
            var imageBrush = new ImageBrush();
            imageBrush.ImageSource = taskIcon.Source;
            var taskManager = new ProgramIcon() {
                ProgramUC = new ProgramChildWindow(),
                ProcessName = processName
            };
            taskManager.ProgramUC.IsEnabled = false;
            taskManager.ProgramUC.ProcessName = processName;
            taskManager.ProgramUC.Root.Children.Add(programUc);
            taskManager.IconImage.Source = imageBrush.ImageSource;

            if(programUc.GetType() == typeof(TaskManager))
                ((TaskManager)programUc).OnProcessClosed += Desktop_OnProcessClosed;

            taskManager.OnLoadUserControl += taskManager_OnLoadUserControl;
            IconPanel.Children.Add(taskManager);
        }
开发者ID:gehOS,项目名称:ricOS,代码行数:21,代码来源:Desktop.xaml.cs


注:本文中的System.Windows.Controls.UserControl.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。