/// <summary> /// Returns the value of the property described by the path. /// </summary> /// <param name="source">The object where to start finding the property</param> /// <param name="path">The path of the property separated by period (.)</param> /// <returns>The value of the property</returns> public static object GetPropertyValueFromPath(object source, string path) { var pSource = XAMLHelper.GetSourceFromPath(source, path); var bindingPath = path.Split('.'); var propertyName = bindingPath[bindingPath.Length - 1]; var propertyInfo = pSource.GetType().GetPropertyEx(propertyName); if (propertyInfo == null) { return(null); } return(propertyInfo.GetValue(pSource)); }
/// <summary> /// Set the inlined content of the <see cref="TextBlock"/>. This will clear the previous inline elements. /// If <paramref name="text"/> is null then previous inline will also be cleared. /// </summary> /// <param name="textBlock">The <see cref="TextBlock"/> to set the inline elements to.</param> /// <param name="text">The XAML formated text.</param> public static void SetInlinedText(this TextBlock textBlock, string text) { if (text == null) { textBlock.Inlines.Clear(); return; } if (text.StartsWith("<Inline>") && text.EndsWith("</Inline>")) { textBlock.Inlines.Clear(); textBlock.Inlines.Add(XAMLHelper.ParseToInline(text)); } else { textBlock.Text = text; } }
/// <summary> /// Get the value of the source of the given <see cref="Binding"/>. /// </summary> /// <param name="binding">The <see cref="Binding"/> of interest.</param> /// <returns>The value of the <see cref="DependencyProperty"/>.</returns> public static object GetValue(this Binding binding) => XAMLHelper.GetPropertyValueFromPath(binding.Source, binding.Path.Path);
/// <summary> /// Get the value of the source of the given <see cref="BindingExpression"/>. /// </summary> /// <param name="bindingExpression">The <see cref="BindingExpression"/> of interest.</param> /// <returns>The value of the <see cref="DependencyProperty"/>.</returns> public static object GetValue(this BindingExpression bindingExpression) => XAMLHelper.GetPropertyValueFromPath(bindingExpression.DataItem, bindingExpression.ParentBinding.Path.Path);