验证标签内容等于null或string.Empty

Car*_*r22 2 c# wpf label

我正在尝试检查标签的值是否等于null, " ", string.Empty,但每次我运行编码时,都会收到以下错误:

你调用的对象是空的.

这是我的编码:

if (lblSupplierEmailAddress.Content.ToString() == "") //Error here
{
    MessageBox.Show("A Supplier was selected with no Email Address. Please update the Supplier's Email Address", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
    return;
}
Run Code Online (Sandbox Code Playgroud)

如何检查标签内的字符串值是否等于null?我可能会遗漏一些简单的东西,如果是这样,请忽略我的无能:P

Him*_*ere 5

更改

if (lblSupplierEmailAddress.Content.ToString() == "")
Run Code Online (Sandbox Code Playgroud)

if (String.IsNullOrEmpty((string) lblSupplierEmailAddress.Content)
Run Code Online (Sandbox Code Playgroud)

什么时候lblSupplierEmailAddress.Content实际上null你当然可以不打电话ToString,因为它会导致NullReferenceException.但是静态IsNullOrEmpty-方法需要在这方面并返回true,如果Contentnull.