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


C# ViewModelBase.GetType方法代码示例

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


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

示例1: CreateWindow

        Window CreateWindow(ViewModelBase viewModel)
        {
            Type windowType;
            lock (_viewMap)
            {
                if (!_viewMap.ContainsKey(viewModel.GetType()))
                    throw new ArgumentException("viewModel not registered");
                windowType = _viewMap[viewModel.GetType()];
            }

            var window = (Window)Activator.CreateInstance(windowType);
            window.DataContext = viewModel;
            window.Closed += OnClosed;

            lock (_openedWindows)
            {
                // Last window opened is considered the 'owner' of the window.
                // May not be 100% correct in some situations but it is more
                // then good enough for handling dialog windows
                if (_openedWindows.Count > 0)
                {
                    Window lastOpened = _openedWindows[_openedWindows.Count - 1];

                    if (window != lastOpened)
                        window.Owner = lastOpened;
                }

                _openedWindows.Add(window);
            }

            // Listen for the close event
            Messenger.Default.Register<RequestCloseMessage>(window, viewModel, OnRequestClose);

            return window;
        }
开发者ID:notsonormal,项目名称:AstoundingDock,代码行数:35,代码来源:ViewService.cs

示例2: ProvideView

        public static void ProvideView(ViewModelBase vm, ViewModelBase parentVm = null)
        {
            IViewMap map = Maps.SingleOrDefault(x => x.ViewModelType == vm.GetType());

            if (map == null)
                return;

            var viewInstance = Activator.CreateInstance(map.ViewType) as Window;

            if (viewInstance == null)
                throw new InvalidOperationException(string.Format("Can not create an instance of {0}", map.ViewType));

            if (parentVm != null)
            {
                ViewInstance parent = RegisteredViews.SingleOrDefault(x => x.ViewModel == parentVm);

                if (parent != null)
                {
                    Window parentView = parent.View;

                    if (Application.Current.Windows.OfType<Window>().Any(x => Equals(x, parentView)))
                        viewInstance.Owner = parentView;
                }
            }

            viewInstance.DataContext = vm;

            RegisteredViews.Add(new ViewInstance(viewInstance, vm));

            viewInstance.Show();
        }
开发者ID:Scrivener07,项目名称:moddingSuite,代码行数:31,代码来源:DialogProvider.cs

示例3: DelegatePropertyDescriptor

 public DelegatePropertyDescriptor(string descriptor_name, ViewModelBase view_model_base, Type property_type)
     : base(descriptor_name, null)
 {
     this.owner_type = view_model_base.GetType();
     this.property_type = property_type;
     this.descriptor_name = descriptor_name;
     this.view_model_base = view_model_base;
 }
开发者ID:lycilph,项目名称:Projects,代码行数:8,代码来源:DelegatePropertyDescriptor.cs

示例4: GetTemplate

            public static DataTemplate GetTemplate(ViewModelBase param)
            {
                Type t = param.GetType();
                if(!views.ContainsKey(t.Name))
                {
                    views.Add(t.Name, App.Current.Resources[t.Name] as DataTemplate);
                }

                return views[t.Name];
            }
开发者ID:tianzhaodong,项目名称:uwp_AiJianShu,代码行数:10,代码来源:Untils.cs

示例5: GetWindow

        /// <summary>
        /// Gets a <see cref="Window"/> to display the associated content for a <see cref="ViewModelBase"/>
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        private static Window GetWindow(ViewModelBase viewModel)
        {
            if (viewModel == null)
                throw new ArgumentNullException("viewModel");

            // get the view template
            var viewTemplate = Application.Current.TryFindResource(new DataTemplateKey(viewModel.GetType())) as DataTemplate;

            // can't do anything if no view type found for view model
            if (viewTemplate == null) return null;

            // get content from data template
            var view = viewTemplate.LoadContent();

            // if view is Window, just show it - otherwise, create window and wrap content in it
            return view as Window ?? new Window { SizeToContent = SizeToContent.WidthAndHeight, Content = view };
        }
开发者ID:CarlosVV,项目名称:mediavf,代码行数:22,代码来源:WindowService.cs

示例6: TryInjectQueryString

        private void TryInjectQueryString(ViewModelBase viewModel, PhoneApplicationPage page)
        {
            var viewModelType = viewModel.GetType();

            foreach (var pair in page.NavigationContext.QueryString)
            {
                var property = viewModelType.GetPropertyCaseInsensitive(pair.Key);
                if (property == null)
                    continue;

                //property.SetValue(viewModel,MessageBinder.CoerceValue(property.PropertyType, pair.Value, page.NavigationContext),
                //    null
                //    );
                if (property.PropertyType == typeof(int))
                {
                    property.SetValue(viewModel, int.Parse(pair.Value), null);
                }
                else
                {
                    property.SetValue(viewModel, pair.Value, null);
                }
            }
        }
开发者ID:284247028,项目名称:MvvmCross,代码行数:23,代码来源:NavigationService.cs

示例7: GenerateXamlFromClass

        public static string GenerateXamlFromClass(ViewModelBase BindTarget)
        {
            var template1 = "<TextBlock x:Name=\"{0}Label\" FontSize=\"28\" Text=\"{{x:Bind {1}.{0}Label}}\"></TextBlock>";
            var template4 = "<TextBlock x:Name=\"{0}Label\" FontSize=\"28\" Text=\"{{x:Bind {1}.{0}Label}}\" RelativePanel.Below=\"{2}Label\"></TextBlock>";
            var template2 = "<TextBlock x:Name=\"{0}\" Text=\"{{x:Bind {1}.{0}, Mode=OneWay}}\" FontSize=\"28\" RelativePanel.RightOf=\"{0}Label\" RelativePanel.AlignVerticalCenterWith=\"{0}Label\"></TextBlock>";
            var template3 = "<TextBlock x:Name=\"{0}\" Text=\"{{x:Bind {1}.{0}, Mode=OneWay}}\" FontSize=\"28\" RelativePanel.RightOf=\"{0}Label\" RelativePanel.Below=\"{2}\" RelativePanel.AlignVerticalCenterWith=\"{0}Label\"></TextBlock>";

            var t = BindTarget.GetType();

            var props = t.GetRuntimeProperties();

            var sb = new StringBuilder();
            string prev = null;
            foreach (var prop in props)
            {
                if (prop.Name.EndsWith("Label"))
                    continue;

                if (string.IsNullOrEmpty(prev))
                {
                    sb.Append(string.Format(template1, prop.Name, t.Name));
                    sb.AppendLine();
                    sb.Append(string.Format(template2, prop.Name, t.Name));
                }
                else
                {
                    sb.Append(string.Format(template4, prop.Name, t.Name, prev));
                    sb.AppendLine();
                    sb.Append(string.Format(template3, prop.Name, t.Name, prev));
                }

                sb.AppendLine();
                prev = prop.Name;
            }
            return sb.ToString();
        }
开发者ID:MSFTImagine,项目名称:fake-band,代码行数:36,代码来源:CodeGen.cs

示例8: GetTemplate

 public static DataTemplate GetTemplate(ViewModelBase param)
 {
     Type t = param.GetType();
         return App.Current.Resources[t.Name] as DataTemplate;
 }
开发者ID:NamedJohnny,项目名称:Checkmapp-Windows-Phone-,代码行数:5,代码来源:DataTemplateSelector.cs

示例9: GetMultilingualPropertiesFromViewModel

 private IEnumerable<PropertyInfo> GetMultilingualPropertiesFromViewModel(ViewModelBase viewModel)
 {
     return viewModel.GetType().GetProperties().Where(pi => pi.CustomAttributes.Any(ca => ca.AttributeType == typeof(MultilingualAttribute)));
 }
开发者ID:OlegDokuka,项目名称:Platformus,代码行数:4,代码来源:ControllerBase.cs

示例10: Dump

        public static string Dump(ViewModelBase viewModel)
        {
            try
            {
                if (viewModel is LinkRiverViewModel)
                {
                    var linkRiver = viewModel as LinkRiverViewModel;
                    string selectedId = null;
                    if (linkRiver.CurrentSelected != null)
                        selectedId = linkRiver.CurrentSelected.Id;

                    var serializationTpl = new Tuple<Subreddit, string, List<Link>, DateTime, string, string>(linkRiver.Thing, linkRiver.Sort,
                        linkRiver.Links
                            .Take(100)
                            .Select(lvm => ((LinkViewModel)lvm).Link)
                            .ToList(),
                        linkRiver.LastRefresh ?? DateTime.Now, selectedId, linkRiver.Category);
                    var serialized = JsonConvert.SerializeObject(serializationTpl);
                    return JsonConvert.SerializeObject(Tuple.Create("LinkRiverViewModel", serialized));
                }
                else if (viewModel is CommentsViewModel)
                {
                    var comments = viewModel as CommentsViewModel;
                    return JsonConvert.SerializeObject(Tuple.Create("CommentsViewModel", JsonConvert.SerializeObject(Tuple.Create(comments.DumpListing(), comments.Link.Url, comments.Link.Link.Id, comments.LastRefresh))));
                }
                else if (viewModel is LockScreenViewModel
                    || viewModel is SettingsViewModel)
                {
                    return JsonConvert.SerializeObject(Tuple.Create("SettingsViewModel", ""));
                }
                else if (viewModel is PostViewModel)
                {
                    var postViewModel = viewModel as PostViewModel;
                    return JsonConvert.SerializeObject(Tuple.Create("PostViewModel", JsonConvert.SerializeObject(new { Editing = postViewModel.Editing, Kind = postViewModel.Kind, Subreddit = postViewModel.Subreddit, Text = postViewModel.Text, Title = postViewModel.Title, Url = postViewModel.Url })));
                }
                else if (viewModel is ConversationViewModel)
                {
                    var conversationViewModel = viewModel as ConversationViewModel;
                    return JsonConvert.SerializeObject(Tuple.Create("ConversationViewModel",
                        conversationViewModel.IsEditing ? JsonConvert.SerializeObject(new
                        {
                            ActivityId = conversationViewModel.CurrentGroup.Id,
                            Username = conversationViewModel.Reply.Username,
                            Topic = conversationViewModel.Reply.Topic,
                            Contents = conversationViewModel.Reply.Contents,
                            IsReply = conversationViewModel.Reply.IsReply
                        }) :
                        JsonConvert.SerializeObject(new
                        {
                            ActivityId = conversationViewModel.CurrentGroup.Id
                        })));
                }
                else if (viewModel is CommentsContentStreamViewModel)
                {
                    var contentStream = viewModel as CommentsContentStreamViewModel;
                    var currentSelectedUrl = contentStream.CurrentSelected.Url;
                    var currentSelectedId = contentStream.CurrentSelected.Id;
                    return JsonConvert.SerializeObject(Tuple.Create("CommentsContentStreamViewModel", JsonConvert.SerializeObject(Tuple.Create(currentSelectedId, currentSelectedUrl))));
                }
                else if (viewModel is LoginViewModel)
                {
                    return JsonConvert.SerializeObject(Tuple.Create("LoginViewModel", ""));
                }
                else if (viewModel is AboutUserViewModel)
                {
                    return JsonConvert.SerializeObject(Tuple.Create("AboutUserViewModel", JsonConvert.SerializeObject(Tuple.Create(((AboutUserViewModel)viewModel).Thing, ((AboutUserViewModel)viewModel).LastRefresh ?? DateTime.UtcNow))));
                }
                else
                    throw new InvalidOperationException(viewModel.GetType().FullName);
            }
            catch (Exception ex)
            {
                //_logger.Fatal(string.Format("type was {0}", viewModel != null ? viewModel.GetType().FullName : "null"), ex);
                throw;
            }
        }
开发者ID:hippiehunter,项目名称:Baconography,代码行数:76,代码来源:ViewModelDumpUtility.cs

示例11: UpdateNavigationStack

        private void UpdateNavigationStack(ViewModelBase newViewModel)
        {
            if (newViewModel.IsBackNavigationEnabled)
            {
                var newViewModelType = newViewModel.GetType();

                // Hvis den vm der hoppes hen på findes i stacken i forvejen, går man tilbage.
                // Ellers går man frem på en ny vm, som skal tilføjes til stacken.
                if (_navigationStack.Contains(newViewModelType))
                {
                    // Fjern fra stacken indtil den der hoppes tilbage til er fjernet.
                    // Hvis man kun går et step tilbage fjernes kun et element, men man kan også navigere flere steps tilbage, 
                    // hvorved de views der springes over også skal fjernes fra stacken.
                    Type poppedViewModelType = null;

                    while (poppedViewModelType != newViewModelType)
                        poppedViewModelType = _navigationStack.Pop();
                }
                else
                {
                    if (_currentViewModel != null)
                        _navigationStack.Push(_currentViewModel.GetType());
                }
            }
            else
            {
                _navigationStack.Clear();
            }
        }
开发者ID:peter-h4nsen,项目名称:StockBuddy,代码行数:29,代码来源:HostWindowViewService.cs

示例12: GetName

 public string GetName(ViewModelBase model)
 {
     return GetName(model.GetType());
 }
开发者ID:Tauron1990,项目名称:Tauron-Application-Common,代码行数:4,代码来源:CommonLocatorBase.cs


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