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


C# ViewModel.With方法代码示例

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


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

示例1: SetProperties

        public void SetProperties() {
            var button1 = new Button();
            var parentViewModel = new ViewModel();
            var viewModel = new ViewModel();
            ViewModelExtensions.SetParameter(button1, "test");
            ViewModelExtensions.SetParentViewModel(button1, parentViewModel);

            var dObject = new DObject();
            ViewModelExtensions.SetParameter(dObject, "test");
            ViewModelExtensions.SetParentViewModel(dObject, parentViewModel);

            var button2 = new Button() { DataContext = viewModel };
            ViewModelExtensions.SetParameter(button2, "test");
            Assert.AreEqual("test", viewModel.With(x => x as ISupportParameter).Parameter);
            ViewModelExtensions.SetParentViewModel(button2, parentViewModel);
            Assert.AreEqual(parentViewModel, viewModel.With(x => x as ISupportParentViewModel).ParentViewModel);
        }
开发者ID:sk8tz,项目名称:DevExpress.Mvvm.Free,代码行数:17,代码来源:ViewModelExtensionsTests.cs

示例2: ViewHelperTest

        public void ViewHelperTest() {
            var button = new Button();
            var viewModel = new ViewModel();
            var parentViewModel = new ViewModel();
            var textBlock = new TextBlock() { Text = "foo" };
            Assert.AreEqual(null, ViewHelper.GetViewModelFromView(button));
            ViewHelper.InitializeView(button, null, "test", parentViewModel);
            DocumentUIServiceBase.SetTitleBinding(button, TextBlock.TextProperty, textBlock);
            Assert.AreEqual("foo", textBlock.Text);
            button.DataContext = viewModel;
            Assert.AreEqual(viewModel, ViewHelper.GetViewModelFromView(button));
            ViewHelper.InitializeView(button, null, "test", parentViewModel);
            Assert.AreEqual("test", viewModel.With(x => x as ISupportParameter).Parameter);
            Assert.AreEqual(parentViewModel, viewModel.With(x => x as ISupportParentViewModel).ParentViewModel);
            DocumentUIServiceBase.SetTitleBinding(button, TextBlock.TextProperty, textBlock);
            Assert.AreEqual("title", textBlock.Text);
#if !SILVERLIGHT
            viewModel.Title = "title2";
            Assert.AreEqual("title2", textBlock.Text);
#endif
            var dObject = new DObject();
            Assert.AreEqual(null, ViewHelper.GetViewModelFromView(dObject));
            ViewHelper.InitializeView(button, null, "test", parentViewModel);

            var button2 = new Button();
            button2.DataContext = new DocumentViewModel();
            DocumentUIServiceBase.SetTitleBinding(button2, TextBlock.TextProperty, textBlock);
            Assert.AreEqual("foo2", textBlock.Text);

            ViewModelWithAnotherTitle anotherViewModel = new ViewModelWithAnotherTitle();
            ViewHelper.InitializeView(button, anotherViewModel, "test", null);
            Assert.AreEqual(anotherViewModel, button.DataContext);
            DocumentUIServiceBase.SetTitleBinding(button, TextBlock.TextProperty, textBlock);
            Assert.AreEqual("title", textBlock.Text);
            viewModel.Title = "title3";
            Assert.AreEqual("title", textBlock.Text);
        }
开发者ID:JustGitHubUser,项目名称:DevExpress.Mvvm.Free,代码行数:37,代码来源:ViewModelExtensionsTests.cs


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