本文整理汇总了C#中System.Windows.Controls.ContentControl.ClearValue方法的典型用法代码示例。如果您正苦于以下问题:C# ContentControl.ClearValue方法的具体用法?C# ContentControl.ClearValue怎么用?C# ContentControl.ClearValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ContentControl
的用法示例。
在下文中一共展示了ContentControl.ClearValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateSelectedValue
/// <summary>
/// Update the selected value of the of the TreeView based on the value
/// of the currently selected TreeViewItem and the SelectedValuePath.
/// </summary>
/// <param name="item">
/// Value of the currently selected TreeViewItem.
/// </param>
private void UpdateSelectedValue(object item)
{
if (item != null)
{
string path = SelectedValuePath;
if (string.IsNullOrEmpty(path))
{
SelectedValue = item;
}
else
{
// Since we don't have the ability to evaluate a
// BindingExpression, we'll just create a new temporary
// control to bind the value to which we can then copy out
Binding binding = new Binding(path) { Source = item };
ContentControl temp = new ContentControl();
temp.SetBinding(ContentControl.ContentProperty, binding);
SelectedValue = temp.Content;
// Remove the Binding once we have the value (this is
// especially important if the value is a UIElement because
// it should not exist in the visual tree once we've
// finished)
temp.ClearValue(ContentControl.ContentProperty);
}
}
else
{
ClearValue(SelectedValueProperty);
}
}