源绑定不工作Windows Phone 7

时间:2013-04-25 12:11:15

标签: c# windows-phone-7

我正在显示电影列表作为我的Windows Phone 7应用的全景图。点击每部电影我正在播放电影细节。 电影细节,演员表现为枢轴控制。电影细节工作正常 但是当我表演时,它不起作用。我有铸造对象列表。并将源绑定到转换控件中的列表框,但它不显示任何数据。请帮我。以下是我用过的课程。谢谢

MainViewModel.cs

public class MainViewModel
{
    public ObservableCollection<ItemViewModel> MovieItems { get; set; }

 }

ItemViewModel.cs

 public class ItemViewModel : INotifyPropertyChanged
{

     private string _title;
     public string _Title
      {
        get { return _title; }

        set
        {
            if (value != _title)
            {
                _title = value;
                NotifyPropertyChanged("title");
            }
        }
    }


      private ObservableCollection<Cast> _cast;

    public ObservableCollection<Cast> _Cast
    {
        get { return _cast; }

        set
        {
            if (value != _cast)
            {
                _cast = value;
                NotifyPropertyChanged("Cast");
            }
        }
    }
  ..........

}

Cast.cs

public class Cast
 {
      public string name { get; set; }
      public string imagesource { get; set; }


      public Cast(string _name, string _imagesource)
      {
        this.imagesource = _imagesource;
        this.name = _name;
      }
 }
for each movie i have a list of cast objects

MovieModel.cs

                  App.Model.MovieItems.Add(
                   new ItemViewModel()
                   {
                       _Title = data["title"].ToString(),
                       _Cast=casObs,
                      ........
                   }
                   );

moviedetails.xaml

               <ListBox Name="ListBox" Margin="0,0,-12,0" ItemsSource="{Binding _Cast}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Margin="0,0,0,17" Width="432" Height="78">
                            <Canvas>
                                <TextBlock HorizontalAlignment="Center"   VerticalAlignment="Bottom" Margin="120,5,60,3" Text="{Binding name}" TextWrapping="Wrap" FontSize="32" Style="{StaticResource PhoneTextNormalStyle}"/>
                                <Image Height="90" HorizontalAlignment="Left" Margin="12,10,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="90" Source="{Binding imagesource}" />
                            </Canvas>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

2 个答案:

答案 0 :(得分:0)

替换

NotifyPropertyChanged("title");

NotifyPropertyChanged("_Title"); 

并且

NotifyPropertyChanged("Cast");

NotifyPropertyChanged("_Cast");

希望它有所帮助。

答案 1 :(得分:0)

在中间应用转换器,您需要返回ImageSource / BitmapImage,而不是字符串