Windows Phone 72011. 3. 31. 15:13
xaml 상단에 이렇게 datacontext를 연결하고
 
DataContext="{Binding BookViewModel, Source={StaticResource Locator}}"
 
<phone:PhoneApplicationPage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:controls="clr-namespace:HugeFlow.FortuneCoins.Controls"
    xmlns:uc="clr-namespace:HugeFlow.FortuneCoins.Controls"
    xmlns:wp="clr-namespace:HugeFlow.Phone.Controls;assembly=HugeFlow.Phone.Controls"
    xmlns:Custom="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:HugeFlow_CommandPattern_Interactivity="clr-namespace:HugeFlow.CommandPattern.Interactivity;assembly=HugeFlow.MVVM" 
    x:Class="HugeFlow.FortuneCoins.Views.BookView"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"    
    shell:SystemTray.IsVisible="False" DataContext="{Binding BookViewModel, Source={StaticResource Locator}}">
 
behind에서 datacontext를 연결한후
 
private LocationPermissionViewModel _viewModel;
 
     public LocationPermissionView()
     {
         InitializeComponent();
         _viewModel = this.DataContext as LocationPermissionViewModel;
     }
 
그리고 커맨드를 사용할 버튼 이벤트에 이렇게

private void NoButton_Click(object sender, RoutedEventArgs e)
      {
          _viewModel.NoButtonClickCommand.Execute(null);
      }
Posted by 동동(이재동)