C#WPF问题与代码 [英] C# WPF problem with code

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

问题描述

这是我的代码

this is my code

if (TXB.Text == mdate.Content)
                {
                    TXB.Background = new LinearGradientBrush(Colors.Blue, Colors.LightCyan, new Point(0, 0), new Point(1, 1));
                }
                else
                {
                  TXB.Background = new LinearGradientBrush(Colors.Red, Colors.LightCyan, new Point(0, 0), new Point(1, 1));
                }



这是我得到的错误



and this is the error i get

Warning 1   Possible unintended reference comparison; to get a value comparison, cast the right hand side to type 'string'  C:\Users\Kyle\documents\visual studio 2010\Projects\DaysUntill\DaysUntill\MainWindow.xaml.cs    102 11  DaysUntill

推荐答案

是的- Content 不是文本,因此您必须将其强制转换.要了解原因,您必须了解实际的内容.在WPF和Silverlight中,Content 用于指示您可以在对象中拥有丰富的信息.例如,您可能在其中有一个图像和一个复杂的RTF文档.
Yup - Content is not text, so you''ll have to cast it. To understand why, you have to understand what content actually is. In WPF and Silverlight, Content is used to indicate that you can have rich information in an object. You could have an image and a complex RTF document in there for instance.


应为:

it should be:

if (TXB.Text == Convert.ToString(mdate.Content))


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

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