所以我想给TextBlock到ObserverableCollection的Count属性绑定以下XAML.NET 4.5/WPF - 绑定到一个静态属性的属性
<TextBlock x:Name="inactiveCount">
<TextBlock.Text>
<Binding Path="(sockets:Manager.inactiveCollection.Count)" Mode="OneWay" StringFormat="Inactive: {0}" />
</TextBlock.Text>
</TextBlock>
但我运行时收到一个异常程序:
Type reference cannot find type named '{clr-namespace:MyProgram.Net.Sockets;assembly=MyProgram}Manager.inactiveCollection'.
绑定到Manager类中的其他属性工作正常,并且inactiveCollection肯定确实存在作为静态属性。我究竟做错了什么?
编辑
所以每fmunkert的建议,下面,我把它改成
<TextBlock x:Name="inactiveCount">
<TextBlock.Text>
<Binding Path="Count" Source="(sockets:Manager.inactiveCollection)" Mode="OneWay" StringFormat="Inactive: {0}" />
</TextBlock.Text>
</TextBlock>
和它种工作。它显示计数错误的编号,52当集合中有233个对象在管理器的静态构造函数中初始化时。作为对象从集合
编辑2
namespace MyProgram.Net.Sockets
{
//technically this is ProxyClientManager but I renamed it here to make the code smaller
class Manager
{
public static ObservableCollection<ProxyClient> inactiveCollection { get; set; }
static Manager()
{
inactiveCollection = new ObservableCollection<ProxyClient>();
//do stuff to populate inactiveCollection with 233 objects
//do other stuff like start threads to add/remove objects from the collection
}
}
}
也许你应该发布代码与'Manager.inactiveCollection'的声明和代码,显示你如何添加/删除项目。 –
完成。它的实际人群与一些SQL查询相关,它是如何填充的并不是非常重要,在静态构造函数的末尾它包含了233个对象。 – Matt
您需要按照fmunkert的建议,在Source中使用'x:Static'。 –