2010-11-21 6 views
0

私はSilverlightとWP7の新機能で、初めてのアプリケーションを作成しています。私は何を助けて、Caliburn MicroやMVVMツールキットになったのか、そしてMVVMツールキットのビデオを見てから、私はそれを選んだ。しかし、私はLaurentのMIX10ビデオに示されているように、それを動作させるのに本当に困難な時期を迎えています。私はコードの完全な例を見つけることができませんでしたので、Laurentがやったことを複製するためにフレームごとにビデオをほとんど見る必要がありました。私はその場所に基本的なコードがあり、それは私のサービスを打つようだが、私のWP7電話エミュレータに表示されていません。面倒な質問ですが、作業例はどこにでも掲載されていますか?誰かが自分のコードを見て、どこに間違っているのかを教えてくれることを願っていました。ここにあります。私はプロジェクトを実行すると、エラーはありません、エミュレータは正常に表示されますが、テキストは、サービスから返されて表示されません。私は長い間.NETアプリケーションを開発してきましたが、Silverlightと非同期WCFサービスの悩みの種です。どんな助けもありがとう。私はhttp://www.rjmueller.com/DataAccessService/StoneFalcon.svcに設定したWCFサービスからランダムな聖書の詩を返して、GetRandomBibleVerseByIdというメソッドを使って表示します。このメソッドは、パラメータを取らずに、Bibleというエンティティを返します。それは非常に簡単です。答えは非常に明白になるだろうが、私が知らないものは分かりません。MVVM Toolkitを初めて使用すると、表示するために簡単な戻り値を得るための助けが必要です

これは私のサービスと通信し、私のServiceHelperである:ここでは

public class ServiceHelper 
{ 
    public void GetRandomBibleVerseById(Action<Bible, Exception> callback) 
    { 
     var client = new StoneFalconClient(); 

     client.GetRandomBibleVerseByIdCompleted += (s, e) => 
      { 
       var userCallback = e.UserState as Action<Bible, Exception>; 

       if (userCallback == null) 
       { 
        return; 
       } 

       if (e.Error != null) 
       { 
        userCallback(null, e.Error); 
        return; 
       } 
      }; 

     client.GetRandomBibleVerseByIdAsync(callback); 
    } 

は私MainViewModelです:私は結合しています(フィールド:ここで

public class MainViewModel : INotifyPropertyChanged 
{ 
    /// <summary> 
    /// The <see cref="BibleVerse" /> property's name. 
    /// </summary> 
    public const string BibleVersePropertyName = "BibleVerse"; 

    private Bible _bibleVerse; 

    public Bible BibleVerse 
    { 
     get 
     { 
      return _bibleVerse; 
     } 

     set 
     { 
      if (_bibleVerse == value) 
      { 
       return; 
      } 

      _bibleVerse = value; 
      RaisePropertyChanged(BibleVersePropertyName); 
     } 
    } 

    public event PropertyChangedEventHandler PropertyChanged; 

    public void RaisePropertyChanged(string propertyName) 
    { 
     if (PropertyChanged != null) 
     { 
      PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
     } 
    } 

    public string ApplicationTitle 
    { 
     get 
     { 
      return "RJ's Bible Searcher"; 
     } 
    } 

    public string PageName 
    { 
     get 
     { 
      return "Verse of the Day"; 
     } 
    } 

    public MainViewModel() 
    { 
     ServiceHelper helper = new ServiceHelper(); 

     helper.GetRandomBibleVerseById((bibleVerse, error) => 
      { 
       if (error != null) 
       { 
        //show error 
       } 
       else 
       { 
        BibleVerse = new Bible(); 
       } 
      }); 
    } 
} 

は私のXAMLページです現在はテキストと呼ばれています、はい、私は最高の名前ではなく、私はそれを変更しようとしていますが、それは今のところそれです)

<phone:PhoneApplicationPage x:Class="BibleSearcher.wp7.MainPage" 
         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:vm="clr-namespace:BibleSearcher.wp7.ViewModel" 
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         FontFamily="{StaticResource PhoneFontFamilyNormal}" 
         FontSize="{StaticResource PhoneFontSizeNormal}" 
         Foreground="{StaticResource PhoneForegroundBrush}" 
         SupportedOrientations="Portrait" 
         Orientation="Portrait" 
         mc:Ignorable="d" 
         d:DesignWidth="480" 
         d:DesignHeight="768" 
         shell:SystemTray.IsVisible="True" 
         DataContext="{Binding Main, Source={StaticResource Locator}}"> 

<UserControl.Resources> 
    <!--not the best way to do this, 
    does not allow the constructor to take paramaters, uses default constructor 
    when the xaml reaches this point, the viewmodel is created--> 
    <vm:MainViewModel x:Key="MainViewModel" /> 
</UserControl.Resources> 

<!--LayoutRoot contains the root grid where all other page content is placed--> 
<Grid x:Name="LayoutRoot" 
     Background="Transparent"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto" /> 
     <RowDefinition Height="*" /> 
    </Grid.RowDefinitions> 

    <!--TitlePanel contains the name of the application and page title--> 
    <StackPanel x:Name="TitlePanel" 
       Grid.Row="0" 
       Margin="24,24,0,12"> 
     <TextBlock x:Name="ApplicationTitle" 
        Text="RJ's Bible Searcher" 
        Style="{StaticResource PhoneTextNormalStyle}" /> 
     <TextBlock x:Name="PageTitle" 
        Text="Verse of the Day" 
        Margin="-3,-8,0,0" 
        Style="{StaticResource PhoneTextTitle1Style}" FontSize="48" /> 
    </StackPanel> 

    <!--ContentPanel - place additional content here--> 
    <Grid x:Name="ContentGrid" 
      Grid.Row="1" 
      DataContext="{Binding Source={StaticResource MainViewModel}}" > 

     <TextBlock Text="{Binding Path=Text}" 
        Style="{StaticResource PhoneTextNormalStyle}" 
        FontSize="28" Margin="17,8,18,8" d:LayoutOverrides="Width" TextWrapping="Wrap" VerticalAlignment="Top" /> 

    </Grid> 
</Grid> 

答えて

0

はい、ご指摘の通り、あなたは「テキスト」と呼ばれるプロパティにバインドされているが、私はあなたのViewModelで公開されているそのようなプロパティが表示されません!

これは実際にはBibleVerseオブジェクトのプロパティですか?その場合は、バインディングパスは "BibleVerse.Text"にする必要があります

関連する問題