当前位置: 首页>>代码示例>>C#>>正文


C# FrameworkContentElement.SetBinding方法代码示例

本文整理汇总了C#中System.Windows.FrameworkContentElement.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkContentElement.SetBinding方法的具体用法?C# FrameworkContentElement.SetBinding怎么用?C# FrameworkContentElement.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.FrameworkContentElement的用法示例。


在下文中一共展示了FrameworkContentElement.SetBinding方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FixupDataContext

 /// <summary>
 /// If you use a bindable flow document element more than once, you may encounter a "Collection was modified" exception.
 /// The error occurs when the binding is updated because of a change to an inherited dependency property. The most common scenario 
 /// is when the inherited DataContext changes. It appears that an inherited properly like DataContext is propagated to its descendants. 
 /// When the enumeration of descendants gets to a BindableXXX, the dependency properties of that element change according to the new 
 /// DataContext, which change the (non-dependency) properties. However, for some reason, changing the flow content invalidates the 
 /// enumeration and raises an exception. 
 /// To work around this, one can either DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=FrameworkElement}}" 
 /// in code. This is clumsy, so every derived type calls this function instead (which performs the same thing).
 /// See http://code.logos.com/blog/2008/01/data_binding_in_a_flowdocument.html
 /// </summary>
 /// <param name="element"></param>
 public static void FixupDataContext(FrameworkContentElement element)
 {
     Binding b = new Binding(FrameworkContentElement.DataContextProperty.Name);
     // another approach (if this one has problems) is to bind to an ancestor by ElementName
     b.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(FrameworkElement), 1);
     element.SetBinding(FrameworkContentElement.DataContextProperty, b);
 }
开发者ID:Novakov,项目名称:MedicinePlan,代码行数:19,代码来源:Helpers.cs


注:本文中的System.Windows.FrameworkContentElement.SetBinding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。