Example #1
0
        public static void OnScrollOnNewItemChanged(
            DependencyObject d,
            DependencyPropertyChangedEventArgs e)
        {
            var listBox = d as ListBox;

            if (listBox == null)
            {
                return;
            }
            bool oldValue = (bool)e.OldValue, newValue = (bool)e.NewValue;

            if (newValue == oldValue)
            {
                return;
            }
            if (newValue)
            {
                listBox.Loaded   += ListBox_Loaded;
                listBox.Unloaded += ListBox_Unloaded;
                var itemsSourcePropertyDescriptor = TypeDescriptor.GetProperties(listBox)["ItemsSource"];
                itemsSourcePropertyDescriptor.AddValueChanged(listBox, ListBox_ItemsSourceChanged);
            }
            else
            {
                listBox.Loaded   -= ListBox_Loaded;
                listBox.Unloaded -= ListBox_Unloaded;
                if (Associations.ContainsKey(listBox))
                {
                    Associations[listBox].Dispose();
                }
                var itemsSourcePropertyDescriptor = TypeDescriptor.GetProperties(listBox)["ItemsSource"];
                itemsSourcePropertyDescriptor.RemoveValueChanged(listBox, ListBox_ItemsSourceChanged);
            }
        }
Example #2
0
 /// <summary>
 /// Ассоциация расширений с редактором
 /// </summary>
 /// <param name="exts">Массив расширений</param>
 /// <param name="editor">Тип редактора, которым эти файлы открывать</param>
 public static void Register(string[] exts, Type editor)
 {
     if (exts != null)
     {
         if (Associations == null)
         {
             Associations = new Dictionary <string, Type>();
         }
         foreach (string ext in exts)
         {
             if (!Associations.ContainsKey(ext))
             {
                 Associations.Add(ext, editor);
             }
         }
     }
 }
Example #3
0
        /// <summary>
        /// Создание из файла
        /// </summary>
        /// <param name="file">Путь до файла</param>
        public static Editor Create(string file)
        {
            string ext = System.IO.Path.GetExtension(file).ToLower();

            if (Associations != null)
            {
                if (Associations.ContainsKey(ext))
                {
                    // Создание редактора
                    Type   t = Associations[ext];
                    Editor e = Activator.CreateInstance(t) as Editor;
                    e.FileName = file;
                    e.CreateAssocForm();
                    e.Load();
                    return(e);
                }
            }
            return(null);
        }