private void UpdateBinding() { // the CurrentIndex is coerced, so is always valid. var source = Items.OfType <object>().ElementAtOrDefault(CurrentIndex); // update CurrentItem, only used for data binding CurrentItem = source; if (ElementTitleTextBlock != null) { var b = new Binding(TitlePath) { Source = source }; ElementTitleTextBlock.SetBinding(TextBlock.TextProperty, b); } if (ElementMessageTextBlock != null) { var b = new Binding(MessagePath) { Source = source }; ElementMessageTextBlock.SetBinding(TextBlock.TextProperty, b); } if (ElementDetailTextBlock != null) { var b = new Binding(DetailPath) { Source = source }; ElementDetailTextBlock.SetBinding(TextBlock.TextProperty, b); // check if current item has detail value var e = new BindingEvaluator <string>(b); string d = e.GetBindingValue(source); _hasDetail = !string.IsNullOrWhiteSpace(d); } else { _hasDetail = false; } if (_isMouseOver) { if (_hasDetail) { ShowDetail(); } else { HideDetail(); } } }
public override string ToString() { var binding = new Binding(Path) { Converter = Converter, ConverterCulture = ConverterCulture, ConverterParameter = ConverterParameter, Mode = BindingMode.OneTime, FallbackValue = FallbackValue, StringFormat = StringFormat, TargetNullValue = TargetNullValue }; Value = BindingEvaluator <object> .GetBindingValue(binding, Source); return(Value.ToString()); }
private string UndoPop() { if (_undoIndex == 0) { // try getting binding value var binding = GetBindingExpression(TextProperty); if (binding != null) { return(BindingEvaluator <string> .GetBindingValue(binding)); } return(DEFAULT_VALUE); } string text = _undoStack[--_undoIndex]; _undoStack[_undoIndex] = null; return(text); }
/// <summary> /// Evaluates the specified source. /// </summary> /// <param name="source">The object used as a source for the evaluation.</param> /// <param name="binding">The binding.</param> /// <returns>The evaluated binding.</returns> public static T GetBindingValue(Binding binding, object source) { var eval = new BindingEvaluator <T>(binding); return(eval.GetBindingValue(source)); }
/// <summary> /// Evaluates the specified source. /// </summary> /// <param name="bindingExpression">The binding.</param> /// <returns>The evaluated binding.</returns> public static T GetBindingValue(BindingExpression bindingExpression) { var eval = new BindingEvaluator <T>(bindingExpression.ParentBinding); return(eval.GetBindingValue(bindingExpression.DataItem)); }