从可观察集合中获取数据到按钮事件

Getting data from the observable collection to the button event

public ObservableCollection<WordList> MyWordList { get; set; }
    public DictionaryPage()
    {
        InitializeComponent();
        BindingContext = new DictionaryPageViewModel();

        MyWordList = new ObservableCollection<WordList>
        {
            new WordList { Color = "Red", Letter = "A", Word = "Abdomen", Meaning = "Mean : " + "Mean",Detail= "Mean", Voice = "myVoice.mp3" }
    };
        
    }

    private async void PronunciationButton_Clicked(object sender, System.EventArgs e)
    {
        await CrossMediaManager.Current.PlayFromAssembly("HERE HERE HERE");
    }

我有一个像这样的可观察集合,我想把里面的语音值放到下面的按钮事件中。感谢您的帮助

MyWordList是一个class级变量。只需在您的 Clicked 处理程序

中引用它
private async void PronunciationButton_Clicked(object sender, System.EventArgs e)
{
    For each (var word in MyWordList) {
        await CrossMediaManager.Current.PlayFromAssembly(word.Voice);
     }
}