オンラインで豊富な情報を見てきましたが、これを修正するための何かが見つかりませんでした。私はこれにはとても新しいので、これはあなたのためにとても基本的な場合は謝罪します。あなたは私が学ぶのを手伝っています:)NullReferenceExceptionが処理されていません
アプリケーションはうまくいきますが、ユーザーがリストボックスから何も選択せず、代わりに「Do We Match」ボタンを押すとプログラムがクラッシュします。私はそれが彼らが各リストのstarsignをクリックすることを要求するエラーを投げるために必要です(公式のエラーは 'Null参照例外は未処理です)。これまでにその部分について
コード:
私はあなたに感謝し、誰かが役立つことを願って // Method for starsign combinations
public void Combinations()
{
ListBoxItem lbi = (ListBoxItem)yourListBox.SelectedItem;
string yourListBoxValue = (string)lbi.Content;
ListBoxItem lbi2 = (ListBoxItem)partnerListBox.SelectedItem;
string partnerListBoxValue = (string)lbi2.Content;
string listBoxValuesCombined = yourListBoxValue + partnerListBoxValue;
if ((listBoxValuesCombined == "Aries" + "Aries") || (listBoxValuesCombined == "Aries" + "Aries"))
resultTextBlock.Text = "On Fire - this is a hot combination!";
。
ありがとう、魅力のように動作します! :D – AppGirl