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(); } }
private string GetDisplayText(object dataItem) { if (BindingEvaluator == null) { BindingEvaluator = new BindingEvaluator(new Binding(DisplayMember)); } if (dataItem == null) { return string.Empty; } if (string.IsNullOrEmpty(DisplayMember)) { return dataItem.ToString(); } return BindingEvaluator.Evaluate(dataItem); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); Editor = Template.FindName(PartEditor, this) as TextBox; Popup = Template.FindName(PartPopup, this) as Popup; ItemsSelector = Template.FindName(PartSelector, this) as Selector; BindingEvaluator = new BindingEvaluator(new Binding(DisplayMember)); if (Editor != null) { Editor.TextChanged += OnEditorTextChanged; Editor.PreviewKeyDown += OnEditorKeyDown; Editor.LostFocus += OnEditorLostFocus; if (SelectedItem != null) { Editor.Text = BindingEvaluator.Evaluate(SelectedItem); } } if (Popup != null) { Popup.StaysOpen = false; Popup.Opened += OnPopupOpened; Popup.Closed += OnPopupClosed; } if (ItemsSelector != null) { SelectionAdapter = new SelectionAdapter(ItemsSelector); SelectionAdapter.Commit += OnSelectionAdapterCommit; SelectionAdapter.Cancel += OnSelectionAdapterCancel; SelectionAdapter.SelectionChanged += OnSelectionAdapterSelectionChanged; } }
/// <summary> /// Received the notifications when the wrapped event has been raised. /// </summary> /// <param name="sender">source of the event</param> /// <param name="e">arguments of the event</param> private void OnEventRaised(object sender, object e) { BindingEvaluator commandBinding = new BindingEvaluator((FrameworkElement)sender, this.Binding.Binding); ICommand command = commandBinding.Value as ICommand; object commandParameter; if (this.Binding.ParameterBinding is Binding) { BindingEvaluator commandParameterBinding = new BindingEvaluator((FrameworkElement)sender, (Binding)this.Binding.ParameterBinding); commandParameter = commandParameterBinding.Value; } else { commandParameter = this.Binding.Parameter; } if(commandParameter == null && this.Binding.PassEventArgsToCommand) { //TODO: GIANNI - TO BE IMPROVED!!!! if (this.Binding.EventName == "ItemClick") { commandParameter = ((Windows.UI.Xaml.Controls.ItemClickEventArgs)e).ClickedItem; } else { commandParameter = e; } } if (command != null) command.Execute(commandParameter); }
void UpdateGrid() { if (_root == null || ItemsSource == null) { return; } _root.Children.Clear(); _root.ColumnDefinitions.Clear(); _independentValues.Clear(); _dependentValues.Clear(); BindingEvaluator independentBinding = new BindingEvaluator(IndependentValuePath); BindingEvaluator dependentBinding = new BindingEvaluator(DependentValuePath); int column = 0; foreach (var item in ItemsSource) { var independentValue = independentBinding.Eval(item).ToString(); var dependentValue = (long)dependentBinding.Eval(item); _dependentValues.Add(dependentValue); _root.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); TextBlock independentTB = new TextBlock(); independentTB.Text = independentValue; independentTB.FontSize = IndependentValueFontSize; independentTB.Foreground = IndependentValueBrush; independentTB.VerticalAlignment = VerticalAlignment.Center; independentTB.HorizontalAlignment = HorizontalAlignment.Center; independentTB.SetValue(Grid.RowProperty, 3); independentTB.SetValue(Grid.ColumnProperty, column++); _root.Children.Add(independentTB); } Rectangle rc = new Rectangle(); rc.Fill = GridLineBrush; rc.Height = 1; rc.SetValue(Grid.RowProperty, 1); rc.SetValue(Grid.ColumnSpanProperty, column); _root.Children.Add(rc); var min = _dependentValues.Min(); var max = _dependentValues.Max(); long temp = 0; if (min >= 0 && max >= 0) { temp = max; } else if (min < 0 && max >= 0) { temp = max - min; } else if (max < 0) { temp = -min; } var height = (this.ActualHeight - 1 - 30) / temp; for (int i = 0; i < _dependentValues.Count; i++) { var dependentValue = _dependentValues[i]; TextBlock dependentTB = new TextBlock(); dependentTB.Text = dependentValue.ToString(); dependentTB.FontSize = DependentValueFontSize; dependentTB.Foreground = dependentValue >= 0 ? PositiveValueBrush : NegativeValueBrush; dependentTB.VerticalAlignment = dependentValue > 0 ? VerticalAlignment.Top : VerticalAlignment.Bottom; dependentTB.HorizontalAlignment = HorizontalAlignment.Center; dependentTB.SetValue(Grid.RowProperty, dependentValue > 0 ? 2 : 0); dependentTB.SetValue(Grid.ColumnProperty, i); Rectangle dependentRC = new Rectangle(); dependentRC.Fill = dependentValue >= 0 ? PositiveValueBrush : NegativeValueBrush; dependentRC.Height = Math.Abs(height * dependentValue); dependentRC.Margin = new Thickness(20, 0, 20, 0); dependentRC.VerticalAlignment = dependentValue <= 0 ? VerticalAlignment.Top : VerticalAlignment.Bottom; dependentRC.SetValue(Grid.RowProperty, dependentValue <= 0 ? 2 : 0); dependentRC.SetValue(Grid.ColumnProperty, i); _root.Children.Add(dependentRC); _root.Children.Add(dependentTB); } }
public SearchableComboBox() { _valuePathEvaluator = new BindingEvaluator(SearchValuePath); }