本文整理汇总了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);
}
示例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);
}