簡體   English   中英

'System.Windows.Markup.XamlParseException'

[英]'System.Windows.Markup.XamlParseException'

我是Windows Phone 8編程的新手,並且正在使用一個簡單的記事本。 我似乎無法弄清楚這個錯誤。

我想在文本框不再為空時啟用保存按鈕。 我在文本框本身上使用了keyup事件:

 <TextBox x:Name="TextBoxNote" KeyUp="TextBoxNote_KeyUp" />

后面的代碼:

 private void TextBoxNote_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
 {
    if (TextBoxNote.Text == "")
    {
        ApplicationBarSaveButton.IsEnabled = false;
    }
    else
    {
        ApplicationBarSaveButton.IsEnabled = true;
    }
 }

在XAML中,我將IsEnabled設置為false

<shell:ApplicationBarIconButton x:Name="ApplicationBarSaveButton"
           IconUri="/Assets/AppBar/e105-Save.76 (1).png"
           Text="save" IsEnabled="False"
           Click="ApplicationBarIconButton_Click_1" />

如果在文本框中輸入內容,則會出現此錯誤:

System.NullReferenceException was unhandled by user code
  HResult=-2147467261
  Message=Object reference not set to an instance of an object.
  Source=Notepad
  StackTrace:
       at Notepad.WriteNote.TextBoxNote_KeyUp(Object sender, KeyEventArgs e)
       at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
  InnerException: 

在線:

ApplicationBarSaveButton.IsEnabled = true;

關於這個有什么想法嗎?

嘗試這個,

 private void TextBoxNote_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
    {
        ApplicationBarIconButton button= (ApplicationBarIconButton)ApplicationBar.Buttons[0];

        if (TextBoxNote.Text == "")
        {
            button.IsEnabled = false;
        }
        else
        {
            button.IsEnabled = true;
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM