Exemplo n.º 1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public LogFiltersSetting()
        ///
        /// \brief Default constructor.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 10/12/2017
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public LogFiltersSetting()
        {
            InitializeComponent();
            data = new SelectControlData {
                options = Logger.Filters
            };
            SelectControl.Init(data);
        }
Exemplo n.º 2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public SelectDialog(string message, string title, List<string> options, List<int> initialySelected = null, List<bool> enableItems = null, SelectionMode selectionMode = SelectionMode.Single)
        ///
        /// \brief Constructor.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 20/02/2018
        ///
        /// \param message           (string) - The message.
        /// \param title             (string) - The title.
        /// \param options           (List&lt;string&gt;) - Options for controlling the operation.
        /// \param initialySelected (Optional)  (List&lt;int&gt;) - The initially selected.
        /// \param enableItems      (Optional)  (List&lt;bool&gt;) - The enable items.
        /// \param selectionMode    (Optional)  (SelectionMode) - The selection mode.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public SelectDialog(string message, string title, List <string> options, List <int> initiallySelected = null, List <bool> enableItems = null, SelectionMode selectionMode = SelectionMode.Single)
        {
            InitializeComponent();
            this.selectionMode = selectionMode;
            Title = title;
            SelectCtrl.Message       = message;
            SelectCtrl.SelectionMode = selectionMode;
            SelectControlData data = new SelectControlData();

            data.enableItems       = enableItems;
            data.initiallySelected = initiallySelected;
            data.options           = options;
            SelectCtrl.Init(data);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public void Init(SelectControlData data)
        ///
        /// \brief Initializes the given data.
        ///
        /// \par Description.
        ///      Build the control and fill it with data
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 29/08/2017
        ///
        /// \param data  (SelectControlData) - The data.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public void Init(SelectControlData data)
        {
            this.data             = data;
            Label_Text.Content    = Message;
            TextBox_Selected.Text = "";

            // if enabledItem is null - set all items enabled
            if (DisableSelection)
            {
                data.enableItems = Enumerable.Range(0, data.options.Count).Select(i => false).ToList();
            }
            else
            {
                if (data.enableItems == null)
                {
                    data.enableItems = Enumerable.Range(0, data.options.Count).Select(i => true).ToList();;
                }
            }

            // disable the event (in order not to trigger while initiating)
            ListBox_Options.SelectionChanged -= ListBox_Options_SelectionChanged;

            // the clear is needed because the method might be called for update
            ListBox_Options.Items.Clear();

            // fill the list box
            for (int idx = 0; idx < data.options.Count; idx++)
            {
                ListBoxItem listBoxItem = new ListBoxItem();
                listBoxItem.Content   = data.options[idx];
                listBoxItem.IsEnabled = data.enableItems[idx];
                ListBox_Options.Items.Add(listBoxItem);
            }
            ListBox_Options.SelectionMode = SelectionMode;

            // enable the trigger in order that it will be relevant when init of the selection
            ListBox_Options.SelectionChanged += ListBox_Options_SelectionChanged;

            // if the initially selected is not null select all the initially selected
            if (data.initiallySelected != null)
            {
                // If the mode is single - set the selection index to the first option in the list
                if (SelectionMode == SelectionMode.Single)
                {
                    ListBox_Options.SelectedIndex = data.initiallySelected[0];
                }

                // if the selection mode is multiple - Set all the selected indexes
                else
                {
                    foreach (int selectedItemIndex in data.initiallySelected)
                    {
                        ListBox_Options.SelectedItems.Add(ListBox_Options.Items[selectedItemIndex]);
                    }
                }
            }

            // if the initially selected is null - select the first enabled item which
            else
            {
                for (int idx = 0; idx < ListBox_Options.Items.Count; idx++)
                {
                    if (((ListBoxItem)ListBox_Options.Items[idx]).IsEnabled)
                    {
                        ListBox_Options.SelectedIndex = idx;
                        break;
                    }
                }
            }

            // Disable the TextBlock if needed
            TextBox_Selected.IsEnabled = EnableTextBox;

            // if the selection mode is multiply - remove the TextBox
            if (SelectionMode == SelectionMode.Multiple)
            {
                TextBox_Selected.Visibility = Visibility.Collapsed;
            }
        }