У меня главное окно МОФ:WPF MVVM ViewModel конструктор DesignMode
<Window x:Class="NorthwindInterface.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ViewModels="clr-namespace:NorthwindInterface.ViewModels" Title="MainWindow" Height="350" Width="525">
<Window.DataContext>
<ViewModels:MainViewModel />
</Window.DataContext>
<ListView ItemsSource="{Binding Path=Customers}">
</ListView>
</Window>
И в MainViewModel это:
class MainViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = delegate { };
public MainViewModel()
{
Console.WriteLine("test");
using (NorthwindEntities northwindEntities = new NorthwindEntities())
{
this.Customers = (from c in northwindEntities.Customers
select c).ToList();
}
}
public List<Customer> Customers { get;private set; }
Теперь проблема заключается в том, что в designermode я не могу видеть мой MainViewModel, он подчеркивает, что он не может создать экземпляр MainViewModel. Он подключается к базе данных. Вот почему (когда я комментирую код, проблема решена).
Но я не хочу этого. Какие-нибудь решения по лучшим практикам?
И почему эта работа при работе с MVVM:
/// <summary>
/// Initializes a new instance of the <see cref="MainViewModel"/> class.
/// </summary>
public MainViewModel()
{
// Just providing a default Uri to use here...
this.Uri = new Uri("http://www.microsoft.com/feeds/msdn/en-us/rss.xml");
this.LoadFeedCommand = new ActionCommand(() => this.Feed = Feed.Read(this.Uri),() => true);
this.LoadFeedCommand.Execute(null); // Provide default set of behavior
}
Это даже отлично выполняет во время разработки.
A) Что делает DesignerProperties.IsInDesignTool? B) Я не могу найти это свойство в DesignerProperties –
Возможно, это работает только с Silverlight, а не с WPF? – John