wpf TextBlock.GetBindingExpression 返回 NULL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12033021/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 05:01:45  来源:igfitidea点击:

TextBlock.GetBindingExpression returning NULL

c#.netwpf

提问by blue18hutthutt

The following is returning NULL for me, any idea why?

以下是为我返回 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);

The MultiBinding is fine - the properties are valid and it renders on the UI ..I just can't seem to grab the binding expression (x is always NULL)

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

Am I using this method wrong?

我用这个方法错了吗?

回答by Dennis

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.

此方法实际上只是 BindingOperations.GetBindingExpression 方法的便捷包装器。GetBindingExpression 将当前实例和 dp 参数传递给 BindingOperations.GetBindingExpression。

如果您的绑定是 MultiBinding,请使用 BindingOperations.GetMultiBinding。

See "Remarks" section and notes in "Examples" section here.

请参阅此处的“备注”部分和“示例”部分中的注释。