Ejemplo n.º 1
0
        public StatusViewSwitch(ScenarioModel scenarioModel) : this()
        {
            DataContext = scenarioModel;

            tbScenarioName.Text = scenarioModel.ScenarioName;
            ItemView toSelect = null;

            foreach (var state in scenarioModel.AcceptedValues)
            {
                var itemView = new ItemView();
                itemView.Icon    = Icons.Icon.NavigateNext;
                itemView.Content = state;
                itemView.Margin  = new Thickness(0, 0, 0, 1);
                if (scenarioModel.ScenarioValue != null && scenarioModel.ScenarioValue.Equals(state))
                {
                    toSelect = itemView;
                }
                listItemsStates.Children.Add(itemView);
            }

            Loaded += (o, e) =>
            {
                if (toSelect != null)
                {
                    toSelect.Selected = true;
                    toSelect.Focus();
                }
            };

            listItemsStates.SelectionChanged += (o, e) =>
            {
                var selectedItem = listItemsStates.GetSelectedItems().FirstOrDefault() as ItemView;
                if (selectedItem != null && selectedItem.Content.ToString() != scenarioModel.ScenarioValue)
                {
                    scenarioModel.ScenarioValue = selectedItem.Content.ToString();
                    StateChanged?.Invoke(this, new RoutedEventArgs());
                }
            };
        }