- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个 WPF CustomControl,它有一个名为 SelectedRange 的依赖属性。
在 XAML 中的应用程序中,绑定(bind)设置如下:
SelectedRange="{Binding Source={StaticResource ResourceKey=MainWindow},
Path=GlobalXRange, Mode=TwoWay}"
我在代码中发现 BindingExpression 正在被覆盖(设置为空)。我可以用这段代码确定这一点:
public IRange SelectedRange
{
get { return (IRange)GetValue(SelectedRangeProperty); }
set
{
SetValue(SelectedRangeProperty, value);
Binding b = BindingOperations.GetBinding(this, SelectedRangeProperty);
BindingExpression be =
BindingOperations.GetBindingExpression(this, SelectedRangeProperty);
if (be == null)
{
Console.WriteLine("Binding expression is null!");
}
}
}
事实证明,应用程序启动后 BindingExpression 为 null。
所以我的问题是 - 我如何调试此 BindingExpression 为空的原因 - 例如它是在 XAML 中设置的,我如何才能找到它被设置为 null 的位置?
注意:输出控制台没有绑定(bind)错误
最佳答案
好的伙计们,感谢你们的帮助,我设法解决了这个问题。对于 future 的读者,我是这样做的。
此问题是由 DependencyProperty Precedence 引起的.绑定(bind)到 SelectedRange 的 TwoWay 位于 ItemTemplate 内,并被调用 SetValue(SelectedRangeProperty, value) 的自定义控件覆盖。
WPF 中的解决方案是使用SetCurrentValue(SelectedRangeProperty, value) .
但是,我正在编写一个跨平台控件(Silverlight、WinRT),而这种方法在 SL/WinRT 中不可用。为了解决方法,我必须创建一个绑定(bind)以通过代码中的代理设置 SelectedRangeProperty,例如
var binding = new Binding();
binding.Source = this;
binding.Path = new PropertyPath(SelectedRangeProxyProperty);
binding.Mode = BindingMode.TwoWay;
this.SetBinding(SelectedRangeProperty, binding);
感谢您的帮助,希望这对其他人有帮助!
关于c# - 调试/断点为什么 WPF BindingExpression 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20029968/
System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target propert
我们有一些具有特定数据的派生控件类。这些控件还设置数据错误信息并绑定(bind)到某些特定属性。例如,如果属性 IsNew(假设它存在)为 true,则背景会突出显示。 现在我想知道,如果我使用这些控
测试场景: 我有一个带有 DependencyProperty A 的控件。 我有一个带有属性 A 的 ViewModel,我使用 OneWayToSource 绑定(bind)绑定(bind)到控件
有没有办法获取窗口的所有 BindingExpression 对象? 当需要触发刷新表单的 PropertyChanged 事件数量太高且不是一个好的选择时,我尝试刷新表单。我正在考虑以另一种方式进行
我正在开发基于 WPF/PRISM 的应用程序。父 View (usercontrol)中有许多区域, subview (usercontrol)加载在这些区域中。当加载 subview 时,我可以在
我正在尝试找出绑定(bind)表达式的源属性类型。我想这样做是因为我想使用 UpdateSourceExceptionFilter提供比一般的“无法转换”更有用的错误消息。 在 .NET 4.5 中我
以下代码片段是我的问题的简化版本。基本上,我试图捕获调用 updatesource 时我的 setter 中发生的错误,并将其传播到如下所示的 catch block 。问题是如果在 updateso
无法解决这个问题,我正在努力使这个模板尽可能多才多艺。尝试将 TextBlock 居中时出现以下错误,HorizontalAlignment 不起作用。 System.Windows.Data E
谁能建议一种在 Silverlight 中为 WPF 中存在的 UpdateTarget() 方法创建解决方法的方法?删除 DP 上存在的现有绑定(bind)并手动设置值对我来说不是一个选项。谢谢 最
我的 View 模型中的命令绑定(bind)到我的 WPF 应用程序中的用户控件时遇到问题。这些命令在用户选中或取消选中 checkBox 时运行。话虽如此,这些命令显然绑定(bind)到 check
简而言之(?),我有一个 ListView(目标)单向绑定(bind)到 XmlDataProvider(源)双向绑定(bind)到 TextBox (目标)对控件绑定(bind)使用标准 XAML,
BusyIndicator.xaml
我们都可以在 Visual Studio 输出窗口中看到运行时 BindingExpression 错误。但是我们可以在正在运行的应用程序本身中捕获这些事件吗?我听说 WPF 跟踪...这与此工具有关
我有一些 UI 元素在后面的代码中执行一些特定于 UI 的工作,然后更新数据上下文中的绑定(bind)。 WPF 元素: 后面的代码: /// /// Handle updati
我有一个 WPF CustomControl,它有一个名为 SelectedRange 的依赖属性。 在 XAML 中的应用程序中,绑定(bind)设置如下: SelectedRange="{Bind
我正在将 FrameworkElement 从 WPF 页面上的 StackPanel 转移到以编程方式创建的 StackPanel。在某个时候,我需要刷新绑定(bind)并获取属性值。 此时 Fra
对于出现在输出窗口中的这个错误,我已经搜索了几个小时。我对 WPF 中的绑定(bind)还很陌生,所以我确定我遗漏了什么。 错误全文(每个绑定(bind)路径都有一个,都和这个类似): System.
我在 Windows Phone 7 上使用 Silverlight。 使用 VirtualizingStackPanel 时收到大量“BindingExpression 路径错误”调试消息是否正常?
我需要使用反射来获取 DataGridTemplateColumn 控件中的绑定(bind)值(例如 HyperLinkButton)。有谁知道我该怎么做? 使用 TextBlock 执行此操作似
我试图将我的 W3CError 类型对象的集合绑定(bind)到 WPF ListView 控件。 这是一个不错的 13 行小类... 类 W3CError 公共(public)类型为 ErrorOr
我是一名优秀的程序员,十分优秀!