2010-11-21 23 views
0

görüntülemek için basit bir getiri değeri alma konusunda yardıma ihtiyacım var Silverlight ve WP7 için çok yeni ve ilk uygulamamı yazıyorum. Hangi yardımcıları kullanacağımı anlamaya çalışmak için çok zaman harcadım ve seçimim Caliburn Micro veya MVVM araç setine geldi ve MVVM toolkit'te videoyu gördükten sonra onu seçtim. Ama Laurent'in MIX10 videosunda gösterilen gibi çalışmak için gerçekten zor bir zaman geçiriyorum. Kodun tam bir örneğini bulamadım, bu yüzden Laurent'ın yaptıklarını çoğaltmak için neredeyse kareye göre video izlemem gerekiyordu ve ben sadece halpf yolunu yapıyorum. Temel kodu kullanıyorum ve hizmetime vuruyor gibi görünüyor ama WP7 telefon emülatörümde görünmüyor. Bir yan soru, herhangi bir yerde yayınlanan çalışma örneğidir? Birisinin benim koduma bakıp nerede yanlış gittiğimi söylemesini umuyordum. İşte burada. Projeyi çalıştırdığımda hiç hata yok, emülatör iyi geliyor ancak metin hizmetten döndüğünü göstermiyor. Ben uzun zamandır Net uygulamaları geliştirmekteyim ama Silverlight ve Asynchronous WCF servislerine noob'um. Herhangi bir yardım takdir edilecektir. Btw, uygulama çok basit, tüm o http://www.rjmueller.com/DataAccessService/StoneFalcon.svc kurduğum bir WCF hizmetinden rastgele bir İncil ayet döndürür ve hiçbir parametre alır ve İncil denen bir varlık döndürür GetRandomBibleVerseById adlı bir yöntemle görüntüler. Bu çok basit. Cevabın çok açık olacağını biliyorum ama bilmediklerim, bilmiyorum.MVVM Toolkit'e yeni ve

İşte
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(); 
       } 
      }); 
    } 
} 

benim Xaml sayfası: (ı bağlayıcı am alan İşte

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); } 

benim MainViewModel geçerli:

Bu

benim Servisi ile iletişim kurar benim ServiceHelper olduğunu Şu anda Metin denir, evet, biliyorum, en iyi isim değil, bunu değiştireceğim ama şimdi olduğu gibi)

<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> 

cevap

0

Evet, "Metin" Sen işaret olarak adlandırılan bir özelliğe bağlayıcı olan, ancak böyle bir özellik sizin ViewModel tarafından maruz görmüyorum!

Bu, aslında BibleVerse nesnesinin bir özelliği mi? Öyleyse, ciltleme yolunuz "BibleVerse.Text"

olmalıdır.