Example #1
0
        /// <summary>
        /// Adds a text field with a binding to an object.
        /// </summary>
        /// <param name="name">The text to display as the label of the field</param>
        /// <param name="source">The object source which holds the value of the field</param>
        /// <param name="field">The name of the property which should be displayed in the field</param>
        /// <param name="editable">Whether or not the field can be edited</param>
        /// <param name="converter">A converter to use to convert the value of the binding</param>
        /// <remarks>TODO: Appearantly not working for some reason... :(</remarks>
        public void AddTextField(string name, object source, string field, bool editable = false, IValueConverter converter = null)
        {
            Binding binding = new Binding(field);

            binding.Source = source;
            binding.Mode   = BindingMode.OneWay;
            if (converter != null)
            {
                binding.Converter = converter;
            }

            EditableTextBlock etb = new EditableTextBlock();

            etb.IsEditable  = editable;
            etb.ClickToEdit = editable;
            etb.DataContext = source;
            etb.SetBinding(EditableTextBlock.TextProperty, binding);
            etb.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            etb.Edited           += new EditableTextBlockDelegate(Field_Edited);
            etb.EnteredEditMode  += new EventHandler(Field_EnteredEditMode);
            AddField(name, etb);
        }
Example #2
0
        /// <summary>
        /// Adds a text field with a binding to an object.
        /// </summary>
        /// <param name="name">The text to display as the label of the field</param>
        /// <param name="source">The object source which holds the value of the field</param>
        /// <param name="field">The name of the property which should be displayed in the field</param>
        /// <param name="editable">Whether or not the field can be edited</param>
        /// <param name="converter">A converter to use to convert the value of the binding</param>
        /// <remarks>TODO: Appearantly not working for some reason... :(</remarks>
        public void AddTextField(string name, object source, string field, bool editable = false, IValueConverter converter = null)
        {
            Binding binding = new Binding(field);
            binding.Source = source;
            binding.Mode = BindingMode.OneWay;
            if (converter != null)
                binding.Converter = converter;

            EditableTextBlock etb = new EditableTextBlock();
            etb.IsEditable = editable;
            etb.ClickToEdit = editable;
            etb.DataContext = source;
            etb.SetBinding(EditableTextBlock.TextProperty, binding);
            etb.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            etb.Edited += new EditableTextBlockDelegate(Field_Edited);
            etb.EnteredEditMode += new EventHandler(Field_EnteredEditMode);
            AddField(name, etb);
        }