繁体   English   中英

源绑定无法正常工作Windows Phone 7

[英]source binding not working 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>

更换

NotifyPropertyChanged("title");

NotifyPropertyChanged("_Title"); 

NotifyPropertyChanged("Cast");

NotifyPropertyChanged("_Cast");

希望对您有所帮助。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM