本文整理汇总了C#中GalaSoft.MvvmLight.Test.ViewModel.TestViewModel类的典型用法代码示例。如果您正苦于以下问题:C# TestViewModel类的具体用法?C# TestViewModel怎么用?C# TestViewModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestViewModel类属于GalaSoft.MvvmLight.Test.ViewModel命名空间,在下文中一共展示了TestViewModel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SetCommand_OnBarButtonWithBinding_ParameterShouldUpdate
public void SetCommand_OnBarButtonWithBinding_ParameterShouldUpdate()
{
var value = DateTime.Now.Ticks.ToString();
var vmSource = new TestViewModel
{
Model = new TestModel
{
MyProperty = value
}
};
var vmTarget = new TestViewModel();
var control = new UIBarButtonItemEx();
_binding = new Binding<string, string>(
vmSource,
() => vmSource.Model.MyProperty);
control.SetCommand(
"Clicked",
vmTarget.SetPropertyCommand,
_binding);
Assert.IsNull(vmTarget.TargetProperty);
control.PerformEvent();
Assert.AreEqual(value, vmTarget.TargetProperty);
value += "Test";
vmSource.Model.MyProperty = value;
control.PerformEvent();
Assert.AreEqual(value, vmTarget.TargetProperty);
}
开发者ID:dsfranzi,项目名称:MVVMLight,代码行数:34,代码来源:SetCommandTest.cs
示例2: Binding_ConverterWithFallbackValue_ErrorInConverterShouldUseFallbackValue
public void Binding_ConverterWithFallbackValue_ErrorInConverterShouldUseFallbackValue()
{
var vmSource = new TestViewModel
{
Model = new TestModel
{
MyProperty = "Initial value"
}
};
var vmTarget = new TestViewModel();
const string fallbackValue = "Fallback value";
const string targetNullValue = "Target null value";
_binding = new Binding<string, string>(
vmSource,
() => vmSource.Model.MyProperty,
vmTarget,
() => vmTarget.TargetProperty,
BindingMode.Default,
fallbackValue,
targetNullValue)
.ConvertSourceToTarget(
value =>
{
throw new InvalidCastException("Only for test");
});
Assert.AreEqual(fallbackValue, vmTarget.TargetProperty);
vmSource.Model.MyProperty = "New value";
Assert.AreEqual(fallbackValue, vmTarget.TargetProperty);
}
开发者ID:dsfranzi,项目名称:MVVMLight,代码行数:35,代码来源:BindingTest.cs
示例3: Binding_MultipleLevelsOfNull_ShouldUseFallbackValueThenTargetNullValue
public void Binding_MultipleLevelsOfNull_ShouldUseFallbackValueThenTargetNullValue()
{
var vmSource = new TestViewModel();
var vmTarget = new TestViewModel();
const string fallbackValue = "Fallback value";
const string targetNullValue = "Target null value";
_binding = new Binding<string, string>(
vmSource,
() => vmSource.Nested.Model.MyProperty,
vmTarget,
() => vmTarget.TargetProperty,
BindingMode.Default,
fallbackValue,
targetNullValue);
Assert.AreEqual(fallbackValue, vmTarget.TargetProperty);
vmSource.Nested = new TestViewModel();
Assert.AreEqual(fallbackValue, vmTarget.TargetProperty);
vmSource.Nested.Model = new TestModel();
Assert.AreEqual(targetNullValue, vmTarget.TargetProperty);
vmSource.Nested.Model.MyProperty = DateTime.Now.Ticks.ToString();
Assert.AreEqual(vmSource.Nested.Model.MyProperty, vmTarget.TargetProperty);
}
开发者ID:dsfranzi,项目名称:MVVMLight,代码行数:25,代码来源:BindingTest.cs
示例4: BindingConverter_ConvertDateTimeTwoWayToText_NoError
public void BindingConverter_ConvertDateTimeTwoWayToText_NoError()
{
var now = DateTime.Now;
Vm = new TestViewModel
{
Date = now
};
#if ANDROID
Text = new EditText(Application.Context);
#elif __IOS__
Text = new UITextViewEx();
#endif
this.SetBinding(
() => Vm.Date,
() => Text.Text,
BindingMode.TwoWay)
.ConvertSourceToTarget(d => d.Date.ToShortDateString())
.ConvertTargetToSource(d => DateTime.ParseExact(d, "dd/MM/yyyy", CultureInfo.InvariantCulture));
Assert.AreEqual(now, Vm.Date);
Assert.AreEqual(now.ToShortDateString(), Text.Text);
Vm.Date += TimeSpan.FromDays(3);
Assert.AreEqual((now + TimeSpan.FromDays(3)).ToShortDateString(), Text.Text);
var newDateString = "13/04/1971";
var newDate = new DateTime(1971, 4, 13);
Text.Text = newDateString;
Assert.AreEqual(newDateString, Text.Text);
Assert.AreEqual(newDate, Vm.Date);
}
开发者ID:dsfranzi,项目名称:MVVMLight,代码行数:34,代码来源:ConverterTest.cs
示例5: BindingConverter_ConvertDateTimeToText_NoError
public void BindingConverter_ConvertDateTimeToText_NoError()
{
var now = DateTime.Now;
Vm = new TestViewModel
{
Date = now
};
#if ANDROID
Text = new EditText(Application.Context);
#elif __IOS__
Text = new UITextViewEx();
#endif
this.SetBinding(
() => Vm.Date,
() => Text.Text)
.ConvertSourceToTarget(d => d.Date.ToShortDateString());
Assert.AreEqual(now, Vm.Date);
Assert.AreEqual(now.ToShortDateString(), Text.Text);
Vm.Date += TimeSpan.FromDays(3);
Assert.AreEqual((now + TimeSpan.FromDays(3)).ToShortDateString(), Text.Text);
}
开发者ID:dsfranzi,项目名称:MVVMLight,代码行数:27,代码来源:ConverterTest.cs
示例6: SetCommand_OnBarButtonNoValueNoEventName_ClickEventShouldBeUsed
public void SetCommand_OnBarButtonNoValueNoEventName_ClickEventShouldBeUsed()
{
var value = DateTime.Now.Ticks.ToString();
var vmTarget = new TestViewModel();
vmTarget.Configure(value);
var control = new UIBarButtonItemEx();
control.SetCommand(vmTarget.SetPropertyWithoutValueCommand);
Assert.IsNull(vmTarget.TargetProperty);
control.PerformEvent();
Assert.AreEqual(value, vmTarget.TargetProperty);
}
开发者ID:dsfranzi,项目名称:MVVMLight,代码行数:14,代码来源:SetCommandTest.cs
示例7: SetCommand_OnButtonNoValueNoEventName_ClickEventShouldBeUsed
public void SetCommand_OnButtonNoValueNoEventName_ClickEventShouldBeUsed()
{
var value = DateTime.Now.Ticks.ToString();
var vmTarget = new TestViewModel();
vmTarget.Configure(value);
var button = new Button(Application.Context);
button.SetCommand(vmTarget.SetPropertyWithoutValueCommand);
Assert.IsNull(vmTarget.TargetProperty);
button.PerformClick();
Assert.AreEqual(value, vmTarget.TargetProperty);
}
开发者ID:NulledLabs,项目名称:mvvmlight,代码行数:14,代码来源:SetCommandTest.cs
示例8: BindingSource_NewBindingWithPrivateProperty_NoError
public void BindingSource_NewBindingWithPrivateProperty_NoError()
{
// For comparison only
var vmSource = new TestViewModel
{
Model = new TestModel
{
MyProperty = "Initial value"
}
};
var vmTarget = new TestViewModel();
_binding = new Binding<string, string>(
vmSource,
() => vmSource.Model.MyProperty,
vmTarget,
() => vmTarget.TargetProperty);
Assert.AreEqual(vmSource.Model.MyProperty, vmTarget.TargetProperty);
var newValue1 = DateTime.Now.Ticks.ToString();
vmSource.Model.MyProperty = newValue1;
Assert.AreEqual(vmSource.Model.MyProperty, vmTarget.TargetProperty);
// Actual test
VmSourcePrivate = new TestViewModel
{
Model = new TestModel
{
MyProperty = "Initial value"
}
};
VmTarget = new TestViewModel();
_binding = new Binding<string, string>(
VmSourcePrivate,
() => VmSourcePrivate.Model.MyProperty,
VmTarget,
() => VmTarget.TargetProperty);
Assert.AreEqual(VmSourcePrivate.Model.MyProperty, VmTarget.TargetProperty);
var newValue2 = DateTime.Now.Ticks.ToString();
VmSourcePrivate.Model.MyProperty = newValue2;
Assert.AreEqual(VmSourcePrivate.Model.MyProperty, VmTarget.TargetProperty);
}
开发者ID:dsfranzi,项目名称:MVVMLight,代码行数:48,代码来源:BindingSourceTest.cs
示例9: SetCommand_OnButtonExWithSimpleValue_NoError
public void SetCommand_OnButtonExWithSimpleValue_NoError()
{
var value = DateTime.Now.Ticks.ToString();
var vmTarget = new TestViewModel();
var button = new ButtonEx(Application.Context);
button.SetCommand(
"Click",
vmTarget.SetPropertyCommand,
value);
Assert.IsNull(vmTarget.TargetProperty);
button.PerformClick();
Assert.AreEqual(value, vmTarget.TargetProperty);
}
开发者ID:NulledLabs,项目名称:mvvmlight,代码行数:16,代码来源:SetCommandTest.cs
示例10: Binding_OneWayFromCheckBoxToViewModelWithUpdateTrigger_BindingGetsUpdated
public void Binding_OneWayFromCheckBoxToViewModelWithUpdateTrigger_BindingGetsUpdated()
{
var vm = new TestViewModel
{
Model = new TestModel()
};
var control1 = new UISwitchEx();
var binding = new Binding<bool, string>(
control1,
() => control1.On,
vm,
() => vm.Model.MyProperty);
Assert.AreEqual("False", vm.Model.MyProperty);
Assert.IsFalse(control1.On);
control1.On = true;
Assert.AreEqual("True", vm.Model.MyProperty);
Assert.IsTrue(control1.On);
}
开发者ID:NulledLabs,项目名称:mvvmlight,代码行数:21,代码来源:UpdateTriggerImplicitTest.cs
示例11: Binding_OneWayFromCheckBoxToViewModelWithUpdateTrigger_BindingGetsUpdated
public void Binding_OneWayFromCheckBoxToViewModelWithUpdateTrigger_BindingGetsUpdated()
{
var vm = new TestViewModel
{
Model = new TestModel()
};
var control1 = new CheckBox(Application.Context);
var binding = new Binding<bool, string>(
control1,
() => control1.Checked,
vm,
() => vm.Model.MyProperty);
Assert.AreEqual("False", vm.Model.MyProperty);
Assert.IsFalse(control1.Checked);
control1.Checked = true;
Assert.AreEqual("True", vm.Model.MyProperty);
Assert.IsTrue(control1.Checked);
}
开发者ID:NulledLabs,项目名称:mvvmlight,代码行数:21,代码来源:UpdateTriggerImplicitTest.cs
示例12: Binding_OneWayFromCheckBoxToViewModelWithObserveEvent_BindingGetsUpdated
public void Binding_OneWayFromCheckBoxToViewModelWithObserveEvent_BindingGetsUpdated()
{
var vm = new TestViewModel
{
Model = new TestModel()
};
var control1 = new CheckBox(Application.Context);
_binding = new Binding<bool, string>(
control1,
() => control1.Checked,
vm,
() => vm.Model.MyProperty)
.ObserveSourceEvent<CompoundButton.CheckedChangeEventArgs>("CheckedChange");
Assert.AreEqual("False", vm.Model.MyProperty);
Assert.IsFalse(control1.Checked);
control1.Checked = true;
Assert.AreEqual("True", vm.Model.MyProperty);
Assert.IsTrue(control1.Checked);
}
开发者ID:dsfranzi,项目名称:MVVMLight,代码行数:22,代码来源:ObserveEventTest.cs
示例13: Binding_OneWayFromCheckBoxToViewModelWithObserveEvent_BindingGetsUpdated
public void Binding_OneWayFromCheckBoxToViewModelWithObserveEvent_BindingGetsUpdated()
{
var vm = new TestViewModel
{
Model = new TestModel()
};
var control1 = new CheckBox(Application.Context);
var binding = new Binding<bool, string>(
control1,
() => control1.Checked,
vm,
() => vm.Model.MyProperty)
.ObserveSourceEvent(); // LostFocus doesn't work programatically with CheckBoxes
Assert.AreEqual("False", vm.Model.MyProperty);
Assert.IsFalse(control1.Checked);
control1.Checked = true;
Assert.IsTrue(control1.Checked);
Assert.AreEqual("True", vm.Model.MyProperty);
}
开发者ID:NulledLabs,项目名称:mvvmlight,代码行数:22,代码来源:ObserveEventLostFocusTest.cs
示例14: BindingTarget_NewBindingWithPrivateProperty_NoError
public void BindingTarget_NewBindingWithPrivateProperty_NoError()
{
VmSource = new TestViewModel
{
Model = new TestModel
{
MyProperty = "Initial value"
}
};
VmTargetPrivate = new TestViewModel();
_binding = new Binding<string, string>(
VmSource,
() => VmSource.Model.MyProperty,
VmTargetPrivate,
() => VmTargetPrivate.TargetProperty);
Assert.AreEqual(VmSource.Model.MyProperty, VmTargetPrivate.TargetProperty);
var newValue = DateTime.Now.Ticks.ToString();
VmSource.Model.MyProperty = newValue;
Assert.AreEqual(VmSource.Model.MyProperty, VmTargetPrivate.TargetProperty);
}
开发者ID:dsfranzi,项目名称:MVVMLight,代码行数:23,代码来源:BindingTargetTest.cs
示例15: Binding_OneWayFromViewModelToCheckBox_BindingGetsUpdated
public void Binding_OneWayFromViewModelToCheckBox_BindingGetsUpdated()
{
var vm = new TestViewModel
{
Model = new TestModel()
};
var control1 = new UISwitchEx();
_binding = new Binding<string, bool>(
vm,
() => vm.Model.MyProperty,
control1,
() => control1.On);
Assert.AreEqual(null, vm.Model.MyProperty);
Assert.IsFalse(control1.On);
vm.Model.MyProperty = "True";
Assert.AreEqual("True", vm.Model.MyProperty);
Assert.IsTrue(control1.On);
}
开发者ID:dsfranzi,项目名称:MVVMLight,代码行数:21,代码来源:ObserveEventTest.cs
示例16: Binding_OneWayFromEditTextToViewModelWithUpdateTrigger_BindingGetsUpdated
public void Binding_OneWayFromEditTextToViewModelWithUpdateTrigger_BindingGetsUpdated()
{
var vm = new TestViewModel
{
Model = new TestModel()
};
var control1 = new UITextViewEx();
_binding = new Binding<string, string>(
control1,
() => control1.Text,
vm,
() => vm.Model.MyProperty)
.ObserveSourceEvent("Changed");
Assert.AreEqual(string.Empty, control1.Text);
Assert.AreEqual(control1.Text, vm.Model.MyProperty);
var value = DateTime.Now.Ticks.ToString();
control1.Text = value;
Assert.AreEqual(value, control1.Text);
Assert.AreEqual(control1.Text, vm.Model.MyProperty);
}
开发者ID:dsfranzi,项目名称:MVVMLight,代码行数:23,代码来源:ObserveEventTest.cs
示例17: Binding_TwoWayFromEditTextToViewModelWithUpdateTrigger_BindingGetsUpdated
public void Binding_TwoWayFromEditTextToViewModelWithUpdateTrigger_BindingGetsUpdated()
{
var vm = new TestViewModel
{
Model = new TestModel()
};
var control1 = new UITextViewEx();
var binding = new Binding<string, string>(
control1,
() => control1.Text,
vm,
() => vm.Model.MyProperty,
BindingMode.TwoWay)
.UpdateSourceTrigger(UpdateTriggerMode.PropertyChanged);
Assert.AreEqual(string.Empty, control1.Text);
Assert.AreEqual(control1.Text, vm.Model.MyProperty);
var value = DateTime.Now.Ticks.ToString();
control1.Text = value;
Assert.AreEqual(value, control1.Text);
Assert.AreEqual(control1.Text, vm.Model.MyProperty);
value += "Suffix";
vm.Model.MyProperty = value;
Assert.AreEqual(value, vm.Model.MyProperty);
Assert.AreEqual(vm.Model.MyProperty, control1.Text);
}
开发者ID:NulledLabs,项目名称:mvvmlight,代码行数:29,代码来源:UpdateTriggerPropertyChangedTest.cs
示例18: SetCommand_OnButtonWithBinding_ParameterShouldUpdate
public void SetCommand_OnButtonWithBinding_ParameterShouldUpdate()
{
var value = DateTime.Now.Ticks.ToString();
var vmSource = new TestViewModel
{
Model = new TestModel
{
MyProperty = value
}
};
var vmTarget = new TestViewModel();
var button = new Button(Application.Context);
var binding = new Binding<string, string>(
vmSource,
() => vmSource.Model.MyProperty);
button.SetCommand(
"Click",
vmTarget.SetPropertyCommand,
binding);
Assert.IsNull(vmTarget.TargetProperty);
button.PerformClick();
Assert.AreEqual(value, vmTarget.TargetProperty);
value += "Test";
vmSource.Model.MyProperty = value;
button.PerformClick();
Assert.AreEqual(value, vmTarget.TargetProperty);
}
开发者ID:NulledLabs,项目名称:mvvmlight,代码行数:34,代码来源:SetCommandTest.cs
示例19: Binding_TwoWayFromViewModelToCheckBoxWithUpdateTrigger_BindingGetsUpdated
public void Binding_TwoWayFromViewModelToCheckBoxWithUpdateTrigger_BindingGetsUpdated()
{
var vm = new TestViewModel
{
Model = new TestModel()
};
var control1 = new UISwitchEx();
_binding = new Binding<string, bool>(
vm,
() => vm.Model.MyProperty,
control1,
() => control1.On,
BindingMode.TwoWay)
.ObserveTargetEvent("ValueChanged");
Assert.AreEqual(null, vm.Model.MyProperty);
Assert.IsFalse(control1.On);
vm.Model.MyProperty = "True";
Assert.AreEqual("True", vm.Model.MyProperty);
Assert.IsTrue(control1.On);
control1.On = false;
Assert.IsFalse(control1.On);
Assert.AreEqual("False", vm.Model.MyProperty);
}
开发者ID:dsfranzi,项目名称:MVVMLight,代码行数:27,代码来源:ObserveEventTest.cs
示例20: SetCommand_OnCheckBoxWithSimpleValueNoEventName_ClickEventShouldBeUsed
public void SetCommand_OnCheckBoxWithSimpleValueNoEventName_ClickEventShouldBeUsed()
{
var value = DateTime.Now.Ticks.ToString();
var vmTarget = new TestViewModel();
var checkBox = new CheckBox(Application.Context);
checkBox.SetCommand<string, CompoundButton.CheckedChangeEventArgs>(
vmTarget.SetPropertyCommand,
value);
Assert.IsNull(vmTarget.TargetProperty);
checkBox.PerformClick();
Assert.AreEqual(value, vmTarget.TargetProperty);
}
开发者ID:NulledLabs,项目名称:mvvmlight,代码行数:15,代码来源:SetCommandTest.cs
注:本文中的GalaSoft.MvvmLight.Test.ViewModel.TestViewModel类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论