Пример #1
0
        /// <summary>
        /// Handles the <see cref="Selector.SelectionChanged"/> event for the "Variable" <see
        /// cref="ListView"/>.</summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="SelectionChangedEventArgs"/> object containing event data.</param>
        /// <remarks>
        /// <b>OnVariableSelected</b> updates all dialog controls to reflect the selected item in
        /// the "Variable" list view.</remarks>

        private void OnVariableSelected(object sender, SelectionChangedEventArgs args)
        {
            args.Handled = true;

            // clear data display
            VariableInfo.Clear();
            MinimumInfo.Clear();
            MaximumInfo.Clear();
            StepSizeInfo.Clear();

            // disable resource display
            ResourceGroup.IsEnabled = false;
            DefeatInfo.Text         = "—"; // em dash
            VictoryInfo.Text        = "—"; // em dash
            ResetToggle.IsChecked   = false;
            LimitToggle.IsChecked   = false;

            // retrieve selected item, if any
            VariableClass variable = VariableList.SelectedItem as VariableClass;

            if (variable == null)
            {
                return;
            }

            // show target range and step size
            MinimumInfo.Text  = variable.Format(variable.Minimum, false);
            MaximumInfo.Text  = variable.Format(variable.Maximum, false);
            StepSizeInfo.Text = variable.Format(1, false);

            // show additional data for resources
            ResourceClass resource = variable as ResourceClass;

            if (resource != null)
            {
                ResourceGroup.IsEnabled = true;

                ResetToggle.IsChecked = resource.IsResetting;
                LimitToggle.IsChecked = resource.IsLimited;

                if (resource.Defeat != Int32.MinValue)
                {
                    DefeatInfo.Text = resource.Format(resource.Defeat, false);
                }

                if (resource.Victory != Int32.MaxValue)
                {
                    VictoryInfo.Text = resource.Format(resource.Victory, false);
                }
            }

            // show associated informational text
            VariableInfo.Text = String.Join(Environment.NewLine, variable.Paragraphs);
        }