从一个类调用get属性到另一个类
本文关键字:调用 get 另一个 属性 一个 | 更新日期: 2023-09-27 18:11:09
所以有人请告诉我,当我点击列表框中的特定歌曲时,我如何播放视频。我已经解析了RSS提要,并在列表框中显示了所有视频。
我有一个名为Songsdetails的类,它有几个属性
public class Songsdetails
{
public string songname { get; set; }
public string songpic { get; set; }
public string songurl { get; set; }
public string songcode { get; set; }
public string songdescr { get; set; }
public string songtitletags { get; set; }
public string songmetatags { get; set; }
public string songmetadesc { get; set; }
public string songdate { get; set; }
}
我通过以下过程将此歌曲代码调用到videpage . xaml .cs。但是songcode并没有被调用。变量中存在Null
namespace videosongs
{
public partial class Videopage : PhoneApplicationPage
{
// Constructor
public Videopage()
{
InitializeComponent();
Songsdetails songdetails=new Songsdetails();
string code = songdetails.songcode;
string video = "http://www.youtube.com/embed/"+code;
System.Diagnostics.Debug.WriteLine(video);
this.webBrowser.Navigate(new Uri(video));
}
请任何人帮助如何获得歌曲代码。我不明白为什么songcode没有来。通过这首歌代码视频在模拟器中播放。请任何人帮助,错误是什么。以及如何获取songcode值。谢谢。
namespace videosongs
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
// is there network connection available
if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
{
MessageBox.Show("No network connection available!");
return;
}
// start loading XML-data
WebClient downloader = new WebClient();
Uri uri = new Uri("http://www.teluguone.com/videosongs/videoSongsXml.php?cat_id=6", UriKind.Absolute);
downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(VideosongsDownloaded);
downloader.DownloadStringAsync(uri);
}
void VideosongsDownloaded(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Result == null || e.Error != null)
{
MessageBox.Show("There was an error downloading the XML-file!");
}
else
{
//Deserialize if download succeeds
{
XDocument document = XDocument.Parse(e.Result);
XmlSerializer serializer = new XmlSerializer(typeof(Videosongs));
Videosongs videosongs = (Videosongs)serializer.Deserialize(document.CreateReader());
videosongList.ItemsSource = videosongs.Collection;
}
}
}
private void videosongList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBox listBox = sender as ListBox;
if (listBox != null && listBox.SelectedItem != null)
{
Songsdetails song = (Songsdetails)listBox.SelectedItem;
NavigationService.Navigate(new Uri("/Videopage.xaml", UriKind.Relative));
}
}
}
}<<strong> videosongs类/strong>
namespace videosongs
{
[XmlRoot("videosongs")]
public class Videosongs
{
[XmlElement("songsdetails")]
public ObservableCollection<Songsdetails> Collection { get; set; }
}
为您创建的数据载体类定义构造函数始终是一个很好的做法。这将避免空指针异常。正如@germi所说,在这段代码中,邮件问题是您没有设置它。那么如何使用它呢?
谢谢阿伦