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


C# IViewModel.GetType方法代码示例

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


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

示例1: ViewModelCommandManager

        /// <summary>
        /// Initializes a new instance of the <see cref="ViewModelCommandManager" /> class.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="viewModel"/> is <c>null</c>.</exception>
        private ViewModelCommandManager(IViewModel viewModel)
        {
            Argument.IsNotNull("viewModel", viewModel);

            Log.Debug("Creating a ViewModelCommandManager for view model '{0}' with unique identifier '{1}'", viewModel.GetType().FullName, viewModel.UniqueIdentifier);

            _viewModel = viewModel;
            _viewModelType = viewModel.GetType();
            _viewModel.Initialized += OnViewModelInitialized;
            _viewModel.PropertyChanged += OnViewModelPropertyChanged;
            _viewModel.Closed += OnViewModelClosed;

            var properties = new List<PropertyInfo>();
            properties.AddRange(_viewModelType.GetPropertiesEx());

            foreach (var propertyInfo in properties)
            {
                if (propertyInfo.PropertyType.ImplementsInterfaceEx(typeof(ICommand)))
                {
                    _commandProperties.Add(propertyInfo);
                }
            }

            RegisterCommands(false);

            Log.Debug("Created a ViewModelCommandManager for view model '{0}' with unique identifier '{1}'", viewModel.GetType().FullName, viewModel.UniqueIdentifier);
        }
开发者ID:pars87,项目名称:Catel,代码行数:32,代码来源:ViewModelCommandManager.cs

示例2: RegisterViewModel

        /// <summary>
        /// Registers the view model to the <see cref="AuditingManager"/>.
        /// <para />
        /// This helper will automatically unsubscribe from all events when the view model is closed.
        /// </summary>
        /// <param name="viewModel">The view model to register.</param>
        /// <remarks>
        /// This helper will call the <see cref="AuditingManager.OnViewModelCreating"/> and <see cref="AuditingManager.OnViewModelCreated"/>
        /// automatically.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="viewModel" /> is <c>null</c>.</exception>
        public static void RegisterViewModel(IViewModel viewModel)
        {
            Argument.IsNotNull("viewModel", viewModel);

            AuditingManager.OnViewModelCreating(viewModel.GetType());

            SubscribeEvents(viewModel);

            AuditingManager.OnViewModelCreated(viewModel.GetType());
        }
开发者ID:JaysonJG,项目名称:Catel,代码行数:21,代码来源:AuditingHelper.cs

示例3: Export

        /// <summary>
        /// Exports the <paramref name="viewModel" />'s view to the print or clipboard or file.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="exportMode">The export mode.</param>
        /// <param name="dpiX">The dpi X.</param>
        /// <param name="dpiY">The dpi Y.</param>
        /// <exception cref="System.InvalidOperationException"></exception>
        /// <exception cref="System.ArgumentNullException">The <paramref name="viewModel" /> is <c>null</c>.</exception>
        /// <remarks>If <paramref name="exportMode" /> is <see cref="ExportMode.Print" /> then the <paramref name="dpiX" /> and <paramref name="dpiY" /> argument will be ignored.</remarks>
        public virtual void Export(IViewModel viewModel, ExportMode exportMode = ExportMode.Print, double dpiX = 96, double dpiY = 96)
        {
            Argument.IsNotNull("viewModel", viewModel);

            var view = _viewManager.GetViewsOfViewModel(viewModel).OfType<UIElement>().FirstOrDefault();
            if (view == null)
            {
                throw Log.ErrorAndCreateException < InvalidOperationException >("There no an active view for this view model of type '{0}'", viewModel.GetType().FullName);
            }

            var bitmap = CreateImageFromUIElement(view, dpiX, dpiY);

            if (exportMode == ExportMode.Print)
            {
                Print(bitmap);
            }
            else
            {
#if !SILVERLIGHT 
                if (exportMode == ExportMode.File)
                {
                    SaveToFile(bitmap);
                }
                else
                {
                    Clipboard.SetImage(bitmap);
                }
#else
                SaveToFile(bitmap);
#endif
            }
        }
开发者ID:Catel,项目名称:Catel,代码行数:42,代码来源:ViewExportService.cs

示例4: Export

        /// <summary>
        /// Exports the <paramref name="viewModel" />'s view to the print or clipboard or file.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="exportMode">The export mode.</param>
        /// <param name="dpiX">The dpi X.</param>
        /// <param name="dpiY">The dpi Y.</param>
        /// <exception cref="System.InvalidOperationException"></exception>
        /// <exception cref="System.ArgumentNullException">The <paramref name="viewModel" /> is <c>null</c>.</exception>
        /// <remarks>If <paramref name="exportMode" /> is <see cref="ExportMode.Print" /> then the <paramref name="dpiX" /> and <paramref name="dpiY" /> argument will be ignored.</remarks>
        public virtual void Export(IViewModel viewModel, ExportMode exportMode = ExportMode.Print, double dpiX = 96, double dpiY = 96)
        {
            Argument.IsNotNull(() => viewModel);

            var view = _viewManager.GetViewsOfViewModel(viewModel).OfType<UIElement>().FirstOrDefault();
            if (view == null)
            {
                string message = string.Format(CultureInfo.InvariantCulture, "There no an active view for this view model of type '{0}'", viewModel.GetType().FullName);

                Log.Error(message);

                throw new InvalidOperationException(message);
            }

            if (exportMode == ExportMode.Print)
            {
                Print(view);
            }
            else
            {
                var bitmap = CreateImageFromUIElement(view, dpiX, dpiY);
#if !SILVERLIGHT 
                if (exportMode == ExportMode.File)
                {
                    SaveToFile(bitmap);
                }
                else
                {
                    Clipboard.SetImage(bitmap);
                }
#else
                SaveToFile(bitmap);
#endif
            }
        }
开发者ID:JaysonJG,项目名称:Catel,代码行数:45,代码来源:ViewExportService.cs

示例5: Create

        public BindingExpression Create(IViewModel viewModel, String elementId, String targetProperty, Binding binding)
        {
            var type = viewModel.GetType();

            // find property dic
            IDictionary<string, MemberInfo> propertyDic;
            if(!_typeBindingDic.TryGetValue(type, out propertyDic))
            {
                propertyDic = new Dictionary<string, MemberInfo>();
                _typeBindingDic[type] = propertyDic;
            }

            MemberInfo propertyInfo = null;

            if(!propertyDic.TryGetValue(targetProperty, out propertyInfo))
            {
                // find the member...
                propertyInfo = type.GetMember(targetProperty).FirstOrDefault();

                if(propertyInfo == null)
                {
                    return null;
                }
                propertyDic[targetProperty] = propertyInfo;
            }
            var bindingExpression = new BindingExpression(binding, propertyInfo, viewModel);

            return bindingExpression;
        }
开发者ID:rhwilburn,项目名称:MVVM-for-Mono,代码行数:29,代码来源:BindingFactory.cs

示例6: RibbonWindow

        /// <summary>
        /// Initializes a new instance of the <see cref="RibbonWindow"/> class.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        public RibbonWindow(IViewModel viewModel)
        {
            var viewModelType = (viewModel != null) ? viewModel.GetType() : GetViewModelType();
            if (viewModelType == null)
            {
                var viewModelLocator = ServiceLocator.Default.ResolveType<IViewModelLocator>();
                viewModelType = viewModelLocator.ResolveViewModel(GetType());
                if (viewModelType == null)
                {
                    const string error = "The view model of the view could not be resolved. Use either the GetViewModelType() method or IViewModelLocator";
                    throw new NotSupportedException(error);
                }
            }

            _logic = new WindowLogic(this, viewModelType, viewModel);
            _logic.ViewModelChanged += (sender, e) => ViewModelChanged.SafeInvoke(this, e);
            _logic.ViewModelPropertyChanged += (sender, e) => ViewModelPropertyChanged.SafeInvoke(this, e);
            _logic.PropertyChanged += (sender, e) => PropertyChanged.SafeInvoke(this, e);

            Loaded += (sender, e) => _viewLoaded.SafeInvoke(this);
            Unloaded += (sender, e) => _viewUnloaded.SafeInvoke(this);
            DataContextChanged += (sender, e) => _viewDataContextChanged.SafeInvoke(this, new DataContextChangedEventArgs(e.OldValue, e.NewValue));

            // Because the RadWindow does not close when DialogResult is set, the following code is required
            ViewModelChanged += (sender, e) => OnViewModelChanged();

            // Call manually the first time (for injected view models)
            OnViewModelChanged();

            SetBinding(TitleProperty, new Binding("Title"));
        }
开发者ID:AntolGolyDnr,项目名称:Catel.Examples,代码行数:35,代码来源:RibbonWindow.cs

示例7: OnViewModelCreated

        public override void OnViewModelCreated(IViewModel viewModel)
        {
            var viewModelTypeName = viewModel.GetType().Name;

            _appTracker.TrackPageView(viewModelTypeName);

            _appTracker.TrackCustomEvent("ViewModel.Created", viewModelTypeName);
        }
开发者ID:ruisebastiao,项目名称:Catel.Examples,代码行数:8,代码来源:GoogleAnalytics.cs

示例8: OnCommandExecuted

        public override void OnCommandExecuted(IViewModel viewModel, string commandName, ICatelCommand command, object commandParameter)
        {
            base.OnCommandExecuted(viewModel, commandName, command, commandParameter);

            var viewModelName = viewModel != null ? viewModel.GetType().Name : string.Empty;

            _analyticsService.SendCommandAsync(viewModelName, commandName);
        }
开发者ID:WildGums,项目名称:Orc.Analytics,代码行数:8,代码来源:AnalyticsAuditor.cs

示例9: OnViewModelCreated

        public override void OnViewModelCreated(IViewModel viewModel)
        {
            base.OnViewModelCreated(viewModel);

            _viewModelCreationTimes[viewModel.UniqueIdentifier] = DateTime.Now;

            _analyticsService.SendViewModelCreatedAsync(viewModel.GetType().FullName);
        }
开发者ID:WildGums,项目名称:Orc.Analytics,代码行数:8,代码来源:AnalyticsAuditor.cs

示例10: OnViewModelCreated

        public override void OnViewModelCreated(IViewModel viewModel)
        {
            if (OnViewModelCreatedCalled)
            {
                return;
            }

            OnViewModelCreatedCalled = true;
            OnViewModelCreatedType = viewModel.GetType();
        }
开发者ID:justdude,项目名称:DbExport,代码行数:10,代码来源:TestAuditor.cs

示例11: OnViewModelClosed

        public override void OnViewModelClosed(IViewModel viewModel)
        {
            base.OnViewModelClosed(viewModel);

            if (_viewModelCreationTimes.ContainsKey(viewModel.UniqueIdentifier))
            {
                var lifetime = DateTime.Now.Subtract(_viewModelCreationTimes[viewModel.UniqueIdentifier]);

#pragma warning disable 4014
                _analyticsService.SendViewModelClosedAsync(viewModel.GetType().FullName, lifetime);
#pragma warning restore 4014
            }
        }
开发者ID:WildGums,项目名称:Orc.Analytics,代码行数:13,代码来源:AnalyticsAuditor.cs

示例12: BindMethods

        private void BindMethods(IEnumerable<FrameworkElement> elements, IViewModel viewModel) {
            var methods = viewModel.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance);

            foreach (var element in elements) {
                var method = methods.Where(m => m.Name == element.Name).SingleOrDefault();

                if (method == null)
                    continue;

                var command =
                    new DelegateCommand(
                        parameter => method.Invoke(viewModel, parameter == null ? null : new[] {parameter}),
                        parameter => true);

                element.SetValue(ButtonBase.CommandProperty, command);
            }
        }
开发者ID:rho24,项目名称:Rholiver.Mvvm,代码行数:17,代码来源:ViewWeaver.cs

示例13: RegisterViewModel

        /// <summary>
        /// Registers the view model to the <see cref="AuditingManager"/>.
        /// <para />
        /// This helper will automatically unsubscribe from all events when the view model is closed.
        /// </summary>
        /// <param name="viewModel">The view model to register.</param>
        /// <remarks>
        /// This helper will call the <see cref="AuditingManager.OnViewModelCreating"/> and <see cref="AuditingManager.OnViewModelCreated"/>
        /// automatically.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="viewModel" /> is <c>null</c>.</exception>
        public static void RegisterViewModel(IViewModel viewModel)
        {
            Argument.IsNotNull("viewModel", viewModel);

            var isAuditingEnabled = AuditingManager.IsAuditingEnabled;
            if (isAuditingEnabled)
            {
                AuditingManager.OnViewModelCreating(viewModel.GetType());
            }

            SubscribeEvents(viewModel);

            if (isAuditingEnabled)
            {
                AuditingManager.OnViewModelCreated(viewModel);
            }
        }
开发者ID:matthijskoopman,项目名称:Catel,代码行数:28,代码来源:AuditingHelper.cs

示例14: TryCacheViewModel

        public virtual void TryCacheViewModel(INavigationContext context, object view, IViewModel viewModel)
        {
            if (context.NavigationMode == NavigationMode.Back)
                return;
            view = ToolkitExtensions.GetUnderlyingView<object>(view);
            Type type = view.GetType();

            List<IViewModel> list;
            if (!_cachedViewModels.TryGetValue(type, out list))
            {
                list = new List<IViewModel>();
                _cachedViewModels[type] = list;
            }
            list.Insert(0, viewModel);
            if (Tracer.TraceInformation)
                Tracer.Info("Navigation cache - the view model {0} was cached, navigation mode: {1}, view: {2}",
                    viewModel.GetType(), context.NavigationMode, type);
        }
开发者ID:dbeattie71,项目名称:MugenMvvmToolkit,代码行数:18,代码来源:DefaultNavigationCachePolicy.cs

示例15: BindProperties

        private void BindProperties(IEnumerable<FrameworkElement> elements, IViewModel viewModel) {
            var properties = viewModel.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (var element in elements) {
                var property = properties.Where(p => p.Name == element.Name).SingleOrDefault();

                if (property == null)
                    continue;

                var binding = new Binding(element.Name) {
                                                            Mode = BindingMode.TwoWay,
                                                            Converter = _defaultConverters.Where(c => c.Type == property.PropertyType)
                                                                .Select(c => c.Converter).FirstOrDefault()
                                                        };


                var binder = _binderProvider.GetFor(element);

                binder.BindIfNotAlready(element, binding);
            }
        }
开发者ID:rho24,项目名称:Rholiver.Mvvm,代码行数:21,代码来源:ViewWeaver.cs


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