c# - TextBlock.GetBindingExpression 返回 NULL

标签 c# .net wpf

以下为我返回 NULL,知道为什么吗?

MultiBinding collectionRange = new MultiBinding();
collectionRange.Bindings.Add(new Binding("CurrentPosition") { Source = View });
collectionRange.Bindings.Add(new Binding("Count") { Source = View });
collectionRange.StringFormat = "{0} of {1}";
tbFooter.SetBinding(TextBlock.TextProperty, collectionRange);
var x = tbFooter.GetBindingExpression(TextBlock.TextProperty);

MultiBinding 很好 - 属性有效并且它在 UI 上呈现..我似乎无法获取绑定(bind)表达式(x 始终为 NULL)

我是不是用错了这个方法?

最佳答案

This method is really just a convenience wrapper around the BindingOperations.GetBindingExpression method. GetBindingExpression passes the current instance and the dp parameter to BindingOperations.GetBindingExpression.

If your binding is a MultiBinding, use BindingOperations.GetMultiBinding.

参见“备注”部分和“示例”部分中的注释 here .

关于c# - TextBlock.GetBindingExpression 返回 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12033021/

相关文章:

c# - 在某些条件下序列化时忽略属性

c# - ASP.NET Core 项目中缺少 SqlDataAdapter

c# - 如何对Android Seekbars做限制,不让用户直接移动?

WPF ListView : Is it possible for rows to have subrows?

WPF Datagrid 右对齐数字列

c# - .net MVC 中的网络摄像头集成

c# - .ToString() 和 .ToString(CultureInfo.CurrentCulture)

c# - 为什么 HttpWebResponse.ContentLength 突然返回 -1?

.net - Windows API代码包: Where is it?

c# - 在 WPF 中将 png 图像合并为单个图像