मैं एक मुख्य WPF खिड़की मिल गया है: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
}
यह भी डिजाइन समय में पूरी तरह से निष्पादित करता है।
ए) DesignerProperties.IsInDesignTool क्या करता है? बी) मैं इस संपत्ति को DesignerProperties –
के तहत नहीं ढूंढ सकता यह केवल सिल्वरलाइट के साथ काम करता है और WPF नहीं? – John