我正在使用Visual Studio 2013的设计器在WPF中创建我的用户控件,而我正在使用MVVM方法.
我正在尝试找到设置我的viewmodel"Design-Time"的最佳方法,以便我立即看到设计师在更改属性值时的效果.我使用了不同的设计和技术来支持这一点,但没有什么是我想要的.我想知道是否有人有更好的想法......
情况(简化):所以我有一个"设备",我希望UserControl显示状态和操作.从上到下:
bool IsConnected {get;}(和状态变化的适当通知)IsChecked={Binding IsConnected, Mode=OneWay框架:
d:DataContext="{Binding DeviceViewModelDesignTime, Source={StaticResource ViewModelLocator}}"
public class ViewModelLocator
{
private static MainWindowViewModel _mainWindowViewModel;
public MainWindowViewModel MainWindowViewModelMainInstance
{
get
{
if (_mainWindowViewModel == null)
{
_mainWindowViewModel = new MainWindowViewModel();
}
return _mainWindowViewModel;
}
}
public DeviceViewModel DeviceViewModelDesignTime
{
get
{
//Custom initialization of the dependencies here
//Could be to create a FakeDeviceModel and assign to constructor
var deviceViewModel = new DeviceViewModel(); …Run Code Online (Sandbox Code Playgroud) 我有一个WPF应用程序,我在其中移动Canvas上的数据.当我尝试使用鼠标像怪物一样移动数据时,问题就出现了.
这是动作的顺序:
这里的一个大问题是我可以回到断言,但它不是断言失败时的数据,而是最后修改过的数据......所以基本上我无法正确调试.
这是堆栈跟踪,从第一个MouseMove开始(注意ShowMessageBoxAssert以及它仍在继续......):
.Models.FCurve.MoveKey(int keyIndex = 3, double keyTime = 1182.0) Line 199 C#
.Models.FCurve.KeyTimeChanged(Models.FCurveKey timeChangeKey = {Models.FCurveKey}) Line 186 + 0x2d bytes C#
.Models.FCurve.AddKeyToArray.AnonymousMethod(object sender = {Models.FCurveKey}, System.EventArgs args = {System.EventArgs}) Line 163 + 0x11 bytes C#
[Native to Managed Transition]
[Managed to Native Transition]
.Models.FCurveKey.OnTimeChanged() Line 45 + 0x14 bytes C#
.Models.FCurveKey..ctor.AnonymousMethod(object sender = {FCurveEditorTestApp.Impl.FCurveKeyImpl}, System.EventArgs args = {System.EventArgs}) Line 18 + 0x8 bytes C#
[Native to Managed Transition]
[Managed to …