private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { SelectionMapping mapping = (SelectionMapping)e.AddedItems.FirstOrDefault(); if (mapping == null || string.CompareOrdinal(Widget.Item.State, mapping.Command) == 0) { return; } Widget.Item.State = mapping.Command; Messenger.Default.Send(new TriggerCommandMessage(Widget.Item, mapping.Command)); }
internal override void SetState() { SelectionMapping itemState = selectionMappings.FirstOrDefault(x => x.Command == Widget.Item.State); DispatcherHelper.ExecuteOnUIThreadAsync(() => { SelectionMapping currentSelection = SelectionComboBox.SelectedItem as SelectionMapping; if (currentSelection != null && string.CompareOrdinal(currentSelection?.Command, itemState?.Command) != 0) { SelectionComboBox.SelectedItem = itemState; } SelectionComboBox.SelectionChanged += Selector_OnSelectionChanged; }); }
/// <summary> /// Get's called after SelectionWidget was loaded and updates the Widgets Selection Dropdown. /// </summary> private void SelectionWidget_Loaded(object sender, global::Windows.UI.Xaml.RoutedEventArgs e) { selectionMappings = new System.Collections.Generic.List <SelectionMapping>(); if (Widget?.Item.CommandDescription?.CommandOptions?.Count > 0) { foreach (OpenHABCommandOptions option in Widget.Item.CommandDescription.CommandOptions) { SelectionMapping mapping = new SelectionMapping(option.Command, option.Label); selectionMappings.Add(mapping); } } if (Widget?.Mappings.Count > 0) { foreach (OpenHABWidgetMapping option in Widget.Mappings) { SelectionMapping mapping = new SelectionMapping(option.Command, option.Label); selectionMappings.Add(mapping); } } SelectionComboBox.ItemsSource = selectionMappings; SetState(); }
private MemberAssignment CreateMemberAssignment <T>(ParameterExpression parameterExpression, SelectionMapping mapping) { var memberInfo = typeof(T).GetProperty(mapping.OutputProperty); var propertyExpression = Expression.Property(parameterExpression, mapping.InputProperty); var assignmentExpression = (Expression)propertyExpression; if (mapping.StringConversionType.HasValue) { assignmentExpression = CreateStringConversionExpression(propertyExpression, mapping.StringConversionType.Value); } return(Expression.Bind(memberInfo, assignmentExpression)); }