Esempio n. 1
0
 /// <summary>
 ///     Handler logic for when a new selected entry is set.
 /// </summary>
 /// <param name="entry"></param>
 /// <returns></returns>
 private void OnSelectedEntrySet(IPreferenceEntry entry)
 {
     if (this is IDatePreference)
     {
         ((IDatePreference)this).Value = ((IDatePreferenceEntry)entry).Name;
     }
     else if (this is INumericPreference)
     {
         ((INumericPreference)this).Value = ((INumericPreferenceEntry)entry).Name;
     }
     else if (this is IStringPreference)
     {
         ((IStringPreference)this).Value = ((IStringPreferenceEntry)entry).Name;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// When overridden in a derived class, returns a <see cref="T:System.Windows.DataTemplate" /> based on custom logic.
        /// </summary>
        /// <param name="item">The data object for which to select the template.</param>
        /// <param name="container">The data-bound object.</param>
        /// <returns>
        /// Returns a <see cref="T:System.Windows.DataTemplate" /> or null. The default value is null.
        /// </returns>
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            FrameworkElement element = container as FrameworkElement;
            IPreferenceEntry entry   = item as IPreferenceEntry;

            if (element == null || entry == null)
            {
                return(null);
            }

            if (entry.Parent.HasPreDefinedChoices && !entry.Parent.HasDirectlyEditableValue)
            {
                // Only predefined choices - regardless of whether they're numeric or not.
                return(element.FindResource("PredefinedStringEntryTemplate") as DataTemplate);
            }
            else if (!entry.Parent.HasPreDefinedChoices && entry.Parent.HasDirectlyEditableValue && entry.Parent.IsNumeric)
            {
                // Numeric value the user can edit.
                return(element.FindResource("NumericEntryTemplate") as DataTemplate);
            }
            else if (entry.Parent.HasPreDefinedChoices && entry.Parent.HasDirectlyEditableValue && !entry.Parent.IsNumeric)
            {
                //Predefined choices, directly editable values and is NOT numeric.
            }
            else if (entry.Parent.HasPreDefinedChoices && entry.Parent.HasDirectlyEditableValue && entry.Parent.IsNumeric)
            {
                //Predefined choices, directly editable values and is numeric.
                return(element.FindResource("NumericPredefinedWithOverridePreferenceEntryTemplate") as DataTemplate);
            }
            else if (!entry.Parent.HasPreDefinedChoices && entry.Parent.HasDirectlyEditableValue && !entry.Parent.IsNumeric)
            {
                // Plain string that the user can edit
                return(element.FindResource("PlainStringEntryTemplate") as DataTemplate);
            }

            return(null);
        }