SORU
4 Ocak 2011, Salı


Nasıl XAML DataContext özelliğini kullanarak bir pencere üzerinde bir ViewModel ayarlarım?

Soru hemen hemen her şeyi söylüyor.

Bir pencere var, ve DataContext ViewModel tam ad kullanarak ayarlamak için çalıştı, ama yanlış bir şey yapıyor gibi görünüyor.

<Window x:Class="BuildAssistantUI.BuildAssistantWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    DataContext="BuildAssistantUI.ViewModels.MainViewModel">

CEVAP
4 Ocak 2011, Salı


Diğer insanlara sağlanan bu çözüm ek olarak iyi ve doğru olan), XAML ViewModel belirtin, ama yine de Görünümü özel ViewModel ayrı bir yolu var. Onları birbirinden ayıran izole test durumları yazmak istediğinizde kullanışlıdır.

App.xaml:

<Application
    x:Class="BuildAssistantUI.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:BuildAssistantUI"
    StartupUri="MainWindow.xaml"
    >
    <Application.Resources>
        <local:MainViewModel x:Key="MainViewModel" />
    </Application.Resources>
</Application>

Ana Pencere İçinde.xaml:

<Window x:Class="BuildAssistantUI.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    DataContext="{StaticResource MainViewModel}"
    />

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Besnik Ibrahimi

    Besnik Ibrah

    27 Mart 2010
  • Matt Stokes

    Matt Stokes

    22 Ocak 2008
  • SavageLuxxxGaming - Daily NBA 2K15 & NBA Live 15 Enjoy And Subscribe!

    SavageLuxxxG

    11 Ocak 2013