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

  • El SalvaLobo

    El SalvaLobo

    10 Temmuz 2006
  • GALERNAYA20

    GALERNAYA20

    19 NİSAN 2011
  • hytchme

    hytchme

    9 Mart 2014