C#WPF对象删除 [英] C# WPF object removing

查看:91
本文介绍了C#WPF对象删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

this is my code

private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
       {
           SolidColorBrush myBrush = new SolidColorBrush(Colors.Red);

           StackPanel SP = new StackPanel();
           SP.Height = 50;
           SP.Width = 300;
           SP.Background = myBrush;

           TextBlock TB = new TextBlock();
           TB.Width = 30;
           TB.Height = 30;
         TB.Text = "World Of Waracrft";

           //wow search
         if (Sois.Properties.Settings.Default.sel == 2)
         {
             if (tb1.Text == "wow")
             {
                 this.sp1.Children.Add(SP);
             }

             else
             {
                 this.sp1.Children.Clear();
             }

         }



       }




这是我的错误
对象引用未设置为对象的实例.

错误是在




this is my error
Object reference not set to an instance of an object.

and the error is at

this.sp1.Children.Clear();

推荐答案

这是因为sp1 == null.

这个问题同时是滥用和垃圾邮件;只是问一个与某个变量相关的错误而不显示其声明和初始化的问题是不礼貌的.我什至没有提到该代码应在调试器下运行.

—SA
This is because sp1 == null.

This question is abuse and spam at the same time; and this is just rude to ask a question about an error related to some variable and not show its declaration and initialization. I don''t even mention that this code should be run under debugger.

—SA


这篇关于C#WPF对象删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆