2016-08-19 2 views
0

백엔드 코드 대신 xaml을 통해 BindingContext를 설정하고 싶습니다. 현재 다음과 같이 할당하고 있습니다 :Xamarin MVVM Light ViewModelLocator xaml에서 BindingContext 설정

public partial class MainPage : ContentPage 
{ 
    public MainPage() 
    { 
     InitializeComponent(); 
     BindingContext = App.Locator.Main; 
    } 
} 

Xaml을 통해 BindingContext를 푸는 방법은 무엇입니까?

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="Codesign.DtpMobilePortable.Views.LoginPage" BindingContext="{Binding LoginPage, Source={StaticResource ViewModelLocator}}"> 
    <StackLayout Spacing="20" Padding="50" VerticalOptions="Center"> 

    <Entry x:Name = "EntryUsername" Text="{Binding EntryUsernameText}" Placeholder = "Username"/> 
    <Entry x:Name = "EntryPassword" Text="{Binding EntryPasswordText}" Placeholder = "Password" IsPassword = "true" /> 

    <Button x:Name = "ButtonLogin" 
         Text = "{Binding LoginButtonText}" 
         TextColor = "White" 
         BackgroundColor = "{Binding LoginButtonColor}" Command="{Binding LoginCommand}"/>  
    </StackLayout> 
</ContentPage> 

App.xaml에게

LoginPage.xaml

<?xml version="1.0" encoding="utf-8" ?> 
<Application xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      xmlns:viewModels="clr-namespace:Codesign.DtpMobilePortable.ViewModels;assembly=Codesign.DtpMobilePortable" 
      x:Class="Codesign.DtpMobilePortable.Views.App"> 
<Application.Resources> 
    <viewModels:ViewModelLocator 
     x:Key="ViewModelLocator" /> 
</Application.Resources> 
</Application> 

을하지만 정적 리소스에 대한 오류가 존재하지 않는 얻을 :이 같은 시도했다.

답변

0

페이지 헤더에 StaticResources 네임 스페이스를 정의해야합니다. 그런

뭔가를해야만 : 내 샘플 코드 내 StaticResources가 위의 xmlnss:local 네임 스페이스에 정의 된

<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
     xmlns:local="clr-namespace:Codesign.DtpMobilePortable;assembly=Codesign.DtpMobilePortable" 
     xmlns:Vm="clr-namespace:Codesign.DtpMobilePortable.ViewModel;assembly=Codesign.DtpMobilePortable" 
     x:Class="Codesign.DtpMobilePortable.Views.LoginPage" 
     BindingContext="{Binding LoginPage, Source={StaticResource ViewModelLocator}}" 

.