using System.Collections; using System.Windows; using System.Windows.Controls; using System.Windows.Data; namespace Developpez.Dotnet.Windows.Controls { /// /// Représente un champ de formulaire lié aux données /// public abstract class BoundFormField : FormField { private BindingBase _binding; /// /// Obtient ou définit le Binding qui produit la valeur du champ /// public BindingBase Binding { get { return _binding; } set { _binding = value; SetBinding(ValueProperty, value); } } /// /// Obtient ou définit la valeur actuelle du champ /// /// N'affectez pas explicitement une valeur à cette propriété; /// elle sera gérée automatiquement par la classe BoundFormField. Le seul /// cas où elle doit être utilisée est pour obtenir la valeur actuelle du /// champ dans les templates via un binding. public object Value { get { return GetValue(ValueProperty); } set { SetValue(ValueProperty, value); } } /// /// Obtient ou définit le style à utiliser pour l'édition du champ /// public Style EditorStyle { get { return (Style)GetValue(EditorStyleProperty); } set { SetValue(EditorStyleProperty, value); } } /// /// Obtient ou définit le style à utiliser pour l'affichage du champ /// public Style DisplayStyle { get { return (Style)GetValue(DisplayStyleProperty); } set { SetValue(DisplayStyleProperty, value); } } /// /// Identifiant de la propriété Value /// public static readonly DependencyProperty ValueProperty = DependencyProperty.Register( "Value", typeof(object), typeof(BoundFormField), new FrameworkPropertyMetadata( null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); /// /// Identifiant de la propriété EditorStyle /// public static readonly DependencyProperty EditorStyleProperty = DependencyProperty.Register("EditorStyle", typeof(Style), typeof(BoundFormField), new PropertyMetadata(null)); /// /// Identifiant de la propriété DisplayStyle /// public static readonly DependencyProperty DisplayStyleProperty = DependencyProperty.Register("DisplayStyle", typeof(Style), typeof(BoundFormField), new PropertyMetadata(null)); } /// /// Représente un champ de formulaire qui affiche ou modifie une donnée textuelle /// sous forme d'une boite de texte. /// [StyleTypedPropertyAttribute(Property = "EditorStyle", StyleTargetType = typeof(TextBox))] [StyleTypedPropertyAttribute(Property = "DisplayStyle", StyleTargetType = typeof(TextBlock))] public class TextFormField : BoundFormField { static TextFormField() { DefaultStyleKeyProperty.OverrideMetadata( typeof(TextFormField), new FrameworkPropertyMetadata(typeof(TextFormField))); } } /// /// Représente un champ de formulaire qui afficher ou modifie une donnée booléenne /// sous forme d'une case à cocher. /// [StyleTypedPropertyAttribute(Property = "EditorStyle", StyleTargetType = typeof(CheckBox))] [StyleTypedPropertyAttribute(Property = "DisplayStyle", StyleTargetType = typeof(CheckBox))] public class CheckBoxFormField : BoundFormField { static CheckBoxFormField() { DefaultStyleKeyProperty.OverrideMetadata(typeof(CheckBoxFormField), new FrameworkPropertyMetadata(typeof(CheckBoxFormField))); } /// /// Obtient ou définit une valeur indiquant si la case à cocher a 3 états (coché, non coché, indéterminé) /// public bool IsThreeState { get { return (bool)GetValue(IsThreeStateProperty); } set { SetValue(IsThreeStateProperty, value); } } /// /// Identifiant de la propriété IsThreeState /// public static readonly DependencyProperty IsThreeStateProperty = DependencyProperty.Register("IsThreeState", typeof(bool), typeof(CheckBoxFormField), new UIPropertyMetadata(false)); } /// /// Représente un champ de formulaire qui affiche ou modifie une donnée à /// choisir dans une liste, sous forme d'une liste déroulante. /// [StyleTypedPropertyAttribute(Property = "EditorStyle", StyleTargetType = typeof(ComboBox))] [StyleTypedPropertyAttribute(Property = "DisplayStyle", StyleTargetType = typeof(ComboBox))] public class ComboBoxFormField : BoundFormField { static ComboBoxFormField() { DefaultStyleKeyProperty.OverrideMetadata(typeof(ComboBoxFormField), new FrameworkPropertyMetadata(typeof(ComboBoxFormField))); } /// /// Obtient ou définit la liste des valeurs à afficher dans la liste déroulante. /// public IEnumerable ItemsSource { get { return (IEnumerable)GetValue(ItemsSourceProperty); } set { SetValue(ItemsSourceProperty, value); } } /// /// Identifiant de la propriété ItemsSource /// public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(ComboBoxFormField), new UIPropertyMetadata(null)); /// /// Obtient ou définit le style des éléments de la liste déroulante /// public Style ItemContainerStyle { get { return (Style)GetValue(ItemContainerStyleProperty); } set { SetValue(ItemContainerStyleProperty, value); } } /// /// Identifiant de la propriété ItemContainerStyle /// public static readonly DependencyProperty ItemContainerStyleProperty = DependencyProperty.Register("ItemContainerStyle", typeof(Style), typeof(ComboBoxFormField), new UIPropertyMetadata(null)); /// /// Obtient ou définit le modèle pour les éléments de la liste déroulante /// public DataTemplate ItemTemplate { get { return (DataTemplate)GetValue(ItemTemplateProperty); } set { SetValue(ItemTemplateProperty, value); } } /// /// Identifiant de la propriété ItemTemplate /// public static readonly DependencyProperty ItemTemplateProperty = DependencyProperty.Register("ItemTemplate", typeof(DataTemplate), typeof(ComboBoxFormField), new UIPropertyMetadata(null)); /// /// Obtient ou définit le membre à afficher pour les éléments de la liste déroulante /// public string DisplayMemberPath { get { return (string)GetValue(DisplayMemberPathProperty); } set { SetValue(DisplayMemberPathProperty, value); } } /// /// Identifiant de la propriété DisplayMemberPath /// public static readonly DependencyProperty DisplayMemberPathProperty = DependencyProperty.Register("DisplayMemberPath", typeof(string), typeof(ComboBoxFormField), new UIPropertyMetadata(null)); /// /// Obtient ou définit le membre à utiliser comme valeur sélectionnée pour les éléments de la liste déroulante /// public string SelectedValuePath { get { return (string)GetValue(SelectedValuePathProperty); } set { SetValue(SelectedValuePathProperty, value); } } /// /// Identifiant de la propriété SelectedValuePath /// public static readonly DependencyProperty SelectedValuePathProperty = DependencyProperty.Register("SelectedValuePath", typeof(string), typeof(ComboBoxFormField), new PropertyMetadata(null)); } /// /// Représente un champ de formulaire qui affiche ou modifie un mot de passe. /// [StyleTypedPropertyAttribute(Property = "EditorStyle", StyleTargetType = typeof(PasswordBox))] [StyleTypedPropertyAttribute(Property = "DisplayStyle", StyleTargetType = typeof(PasswordBox))] public class PasswordBoxFormField : BoundFormField { static PasswordBoxFormField() { DefaultStyleKeyProperty.OverrideMetadata(typeof(PasswordBoxFormField), new FrameworkPropertyMetadata(typeof(PasswordBoxFormField))); } } }