小编GAr*_*ech的帖子

动态设置TextBox文本

我有多个XAML TextBoxes,当TextBox使用C#动态检查TextBox调用方法的方法更改其中的值时,每个XAML 都会操作数组中的相应值.

    <TextBox x:Name="_0_0" TextChanged="_x_y_TextChanged"/>
    <TextBox x:Name="_0_1" TextChanged="_x_y_TextChanged"/>
    <TextBox x:Name="_0_2" TextChanged="_x_y_TextChanged"/>
    // And so on.....
Run Code Online (Sandbox Code Playgroud)

TextBox更改中的值时,每个操作数组中的相应值,使用动态检查TextBox已调用方法的C#方法.

    private void _x_y_TextChanged(object sender, TextChangedEventArgs e)
    {
        TextBox current = (TextBox)sender;
        string currentname = current.Name;
        string rowstring = currentname.Substring(1, 1);

        string columnstring = currentname.Substring(3, 1);

        int row = Convert.ToInt32(rowstring);
        int column = Convert.ToInt32(columnstring);

        // I've then detected the name of the textbox which has called it...
Run Code Online (Sandbox Code Playgroud)

因此,此信息可用于动态存储来自TextBox相应数组索引中的信息 - 或者您想要使用它做什么......

然而,我的问题是: …

c# wpf xaml textbox

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

textbox ×1

wpf ×1

xaml ×1