2011-08-25 86 views

回答

0
  • 你應該實現業務邏輯瀏覽你的目標目錄。準備項目的集合。將這些綁定到列表框
  • 要播放歌曲,請將選定項目綁定到MediaElement。

我會嘗試編譯一些簡單的解決方案並更新,如果您仍然需要進一步的幫助。

更新簡單的解決方案:

的XAML:

<StackPanel Orientation="Vertical"> 
    <ListBox ItemsSource="{Binding}" x:Name="fileList"></ListBox> 
    <MediaElement x:Name="mediaElement" Source="{Binding ElementName=fileList, Path=SelectedItem}"/> 
</StackPanel> 

代碼背後:

public partial class Window1 : Window { 
    ObservableCollection<string> mFileList; 

    public Window1() { 
     InitializeComponent(); 
     GetFiles(@"..\songs"); 

     this.DataContext = mFileList; 

    } 

    private void GetFiles (string folderPath) { 
     string[] files = Directory.GetFiles(folderPath); 
     mFileList = new ObservableCollection<string> (files); 
    } 

} 
+0

謝謝你給了一個idea..i需要代碼snippet.please幫助我。 – Radhika

+0

請檢查更新的解決方案。希望這可以幫助。 – Ujjwal

+0

請幫助我..我有一個更多的問題.. – Radhika

1

爲了使遊戲行爲eexplici上點擊一個按鈕,請參閱本:

的XAML:

<MediaElement x:Name="media" Source="{Binding 
      ElementName=listbox,Path=SelectedItem}" 
      LoadedBehavior="Manual" UnloadedBehavior="Manual"/> 
<Button Click="Button_Click" Height="27" VerticalAlignment="Bottom" 
     HorizontalAlignment="Left" Width="62">Play</Button> 

代碼背後: -

private void Button_Click (object sender, RoutedEventArgs e) { 
     media.Play(); 
} 
0
You need to handle the mediaended event as below :- 

<MediaElement x:Name="media" Source="{Binding ElementName=listbox,Path=SelectedItem}" MediaEnded="media_MediaEnded" 
       ></MediaElement> 

Codebehind :- 
` private void media_MediaEnded (object sender, RoutedEventArgs e) { 
     if (listbox.SelectedIndex < listbox.Items.Count - 1) { 
      listbox.SelectedIndex = listbox.SelectedIndex + 1; 
     }` 
0
You need to handle the mediaended event as below :-  
<MediaElement x:Name="media" Source="{Binding ElementName=listbox,Path=SelectedItem}" Margin="0,119,78,64" MediaEnded="media_MediaEnded" 
       ></MediaElement> 

    private void media_MediaEnded (object sender, RoutedEventArgs e) { 
     if (listbox.SelectedIndex < listbox.Items.Count - 1) { 
      listbox.SelectedIndex = listbox.SelectedIndex + 1; 
     } 

    } 
相關問題