| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 | using System;using System.Windows;using System.Windows.Controls;using System.Windows.Forms;using System.Windows.Media;using Button = System.Windows.Controls.Button;using HorizontalAlignment = System.Windows.HorizontalAlignment;using TextBox = System.Windows.Controls.TextBox;namespace InABox.DynamicGrid{    public class FolderEditorControl : DynamicEditorControl<string>    {        private TextBox Editor;        public Environment.SpecialFolder InitialFolder { get; set; }        public override int DesiredHeight()        {            return 25;        }        public override int DesiredWidth()        {            return int.MaxValue;        }        public override void SetColor(Color color)        {            Editor.Background = new SolidColorBrush(color);        }        public override void SetFocus()        {            Editor.Focus();        }        protected override FrameworkElement CreateEditor()        {            var Grid = new Grid            {                VerticalAlignment = VerticalAlignment.Stretch,                HorizontalAlignment = HorizontalAlignment.Stretch            };            Grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });            Grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(50, GridUnitType.Pixel) });            Grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(50, GridUnitType.Pixel) });            Editor = new TextBox            {                VerticalAlignment = VerticalAlignment.Stretch,                VerticalContentAlignment = VerticalAlignment.Center,                HorizontalAlignment = HorizontalAlignment.Stretch,                Margin = new Thickness(0, 0, 0, 0),                IsEnabled = false            };            //Editor.LostFocus += (o, e) => CheckChanged();            Editor.SetValue(Grid.ColumnProperty, 0);            Editor.SetValue(Grid.RowProperty, 0);            Grid.Children.Add(Editor);            var Select = new Button            {                VerticalAlignment = VerticalAlignment.Stretch,                VerticalContentAlignment = VerticalAlignment.Center,                HorizontalAlignment = HorizontalAlignment.Stretch,                Margin = new Thickness(5, 1, 0, 1),                Content = "Select",                Focusable = false            };            Select.SetValue(Grid.ColumnProperty, 1);            Select.SetValue(Grid.RowProperty, 0);            Select.Click += Select_Click;            Grid.Children.Add(Select);            var Clear = new Button            {                VerticalAlignment = VerticalAlignment.Stretch,                VerticalContentAlignment = VerticalAlignment.Center,                HorizontalAlignment = HorizontalAlignment.Stretch,                Margin = new Thickness(5, 1, 0, 1),                Content = "Clear",                Focusable = false            };            Clear.SetValue(Grid.ColumnProperty, 2);            Clear.SetValue(Grid.RowProperty, 0);            Clear.Click += Clear_Click;            Grid.Children.Add(Clear);            return Grid;        }        private void Select_Click(object sender, RoutedEventArgs e)        {            var dlg = new FolderBrowserDialog();            dlg.SelectedPath = string.IsNullOrWhiteSpace(Editor.Text) ? Environment.GetFolderPath(InitialFolder) : Editor.Text;            if (dlg.ShowDialog() == DialogResult.OK)            {                Editor.Text = dlg.SelectedPath;                CheckChanged();            }            ;        }        private void Clear_Click(object sender, RoutedEventArgs e)        {            Editor.Text = "";            CheckChanged();        }        protected override string RetrieveValue()        {            return Editor.Text;        }        protected override void UpdateValue(string value)        {            Editor.Text = value;        }    }}
 |