2 回答

TA貢獻1784條經驗 獲得超8個贊
你的構造函數FavoriteButtonPopupView可能看起來像這樣
public FavoriteButtonPopupView(string selectedAdvisor)
{
...
}
selectedAdvisor您傳遞的變量是本地范圍的- 這意味著它僅在構造函數中可見,并且該頁面上的其他方法無法訪問它。
您需要做的是創建一個類級別變量,該變量對該類的所有方法都可見。
private string SelectedAdvisor;
public FavoriteButtonPopupView(string selectedAdvisor)
{
// store the parameter in a class level variable so other methods can access it
SelectedAdvisor = selectedAdvisor;
...
}
private void OkayButtonClicked(object sender, EventArgs e)
{
// do something with SelectedAdvisor here
PopupNavigation.Instance.PopAsync();
DisplayAlert("Attention", "You have successfully added Adviser to said List", "Okay");
}
注意 - 這是基本的 C#,與 Xamarin 沒有任何具體關系

TA貢獻1757條經驗 獲得超7個贊
您需要使用okayButton.Click + =事件而不是okayButton += 。
你的代碼應該是這樣的
OKButton.Click += delegate(object sender, EventArgs e) { ..... };
在 C# 中,只能將+=與事件或委托一起使用。您不能將 += 運算符與按鈕實例一起使用
希望這可以幫助
- 2 回答
- 0 關注
- 190 瀏覽
添加回答
舉報