在 WPF/C# 2010 中,如果相关数据对象为空,如何使按钮消失?
我有一个屏幕,用于显示数据表中的数据。 XAML 绑定正在工作并且显示良好。然而,在一个数据字段旁边,我有一个按钮,我想将其用于其他用途。我的问题是,我不希望按钮显示数据字段是否为空或为空。下面是我正在使用的 XAML 和数据对象代码的片段。
按钮的 XAML:
我从隐藏按钮开始。
以下是涵盖样式“DetailButton”的 XAML:
下面是设置 PplOlderFlag 的数据对象代码:
_bOlderFlag = (_sPplOlderInfo.Length > 0);
public bool PplOlderFlag
{
get
{
return _bOlderFlag;
}
}
正如我所说,绑定 (PplOlderInfo) 正在工作并且显示良好。但当 PplOlderInfo 为 null 或为空时,该按钮仍然存在。
我可以很容易地在后面的代码中设置按钮的可见性,但如果我能让它在 XAML 中工作,它看起来会非常光滑。
关于我遗漏了什么或我做错了什么有什么想法吗?
I have a screen that I use to show data from a data table. The XAML bindings are working and it displays fine. However, next to one data field, I have a button that I want to use for other things. My problem is that I don't want the button to show if the data field is null or empty. Below is snippets of the XAML and data object code that I am using.
XAML for the button:
I am starting out with the button hidden.
Here is the XAML that covers the style "DetailButton":
Here is the data object code that sets PplOlderFlag:
_bOlderFlag = (_sPplOlderInfo.Length > 0);
public bool PplOlderFlag
{
get
{
return _bOlderFlag;
}
}
As I said, the binding (PplOlderInfo) is working and show up fine. But the button is still there when the PplOlderInfo is null or empty.
I can set the Visibility of button in the code behind easy enough but it just seems like it would be really slick if I could make it work in the XAML.
Any ideas as to what I am leaving out or what I am doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PplOlderFlag 的类型不应该是 System.Windows.Visibility 类型吗?
在我的测试应用程序中,如果我创建 System.Windows.Visibility 类型的等效属性,我可以根据需要使按钮可见或不可见。
编辑:
从您的代码示例中,我将实现为:
Shouldn't the type of PplOlderFlag be of type System.Windows.Visibility?
In my test app, if I make an equivalent property of type System.Windows.Visibility, I can make the button visible or invisible as required.
Edit:
From your code example, I would implement as: