XAML 永远不会触发TextChanged事件[MAUI]

2skhul33  于 2023-11-14  发布在  其他
关注(0)|答案(1)|浏览(96)

我想确保一旦我的Entry有修改(在写入时),它就会调用TextChanged事件。但发生的情况是,该事件从未被调用。我在ASP.NET it is necessary to put AutoPostBack上看到有类似的东西要添加吗?或者是另一件事?

Xaml

<Entry
    Grid.Row="0"
    Grid.Column="0"
    x:Name="inputUser"
    FontSize="16"
    Text="{Binding Input}"
    Opacity="1.0001"
    Focused="inputUser_Focused"
    TextChanged="inputUser_TextChanged"/>

字符串

C#

void inputUser_TextChanged(object sender, TextChangedEventArgs e)
{
    string oldText = e.OldTextValue;
    string newText = e.NewTextValue;
    if (newText.Length < oldText.Length)
    {
        int diff = oldText.Length - newText.Length;
        for (int i = 0; i < diff; i++)
        {
            DeleteCommandExecute(null);
        }
    }
    else
    {
        int diff = newText.Length - oldText.Length;
        for (int i = 0; i < diff; i++)
        {
            if (newText[oldText.Length+1].ToString()=="*"|| newText[oldText.Length + 1].ToString() == "/"||newText[oldText.Length + 1].ToString() == "+" || newText[oldText.Length + 1].ToString() == "-")
            {
                AddOperatorExecute(newText[oldText.Length + 1].ToString());
            }
            else
            {
                AddNumberExecute(newText[oldText.Length + 1].ToString());
            }
        }
    }
}

cnh2zyt3

cnh2zyt31#

尝试删除“Input”的文本绑定。TextChanged事件与文本绑定奇怪地不兼容。

相关问题