private void DrawSlider(SkinButtonState state)
        {
            var slider = (SkinSlider) SkinElement;
            var art = new SkinArtImage();
            var art2 = new SkinArtImage();
            switch (state) {
                case SkinButtonState.Normal:
                    art = slider.Art.Images.Any(t => t.Type == "BackgroundImage") ? slider.Art.Images.First(t => t.Type == "BackgroundImage") : new SkinArtImage();
                    art2 = slider.Art.Images.Any(t => t.Type == "FocusedImage") ? slider.Art.Images.First(t => t.Type == "FocusedImage") : new SkinArtImage();
                    break;
                case SkinButtonState.Clicked:
                    art = slider.Art.Images.Any(t => t.Type == "BackgroundImage") ? slider.Art.Images.First(t => t.Type == "BackgroundImage") : new SkinArtImage();
                    art2 = slider.Art.Images.Any(t => t.Type == "FocusedImage") ? slider.Art.Images.First(t => t.Type == "FocusedImage") : new SkinArtImage();
                    break;
                case SkinButtonState.Focused:
                    art = slider.Art.Images.Any(t => t.Type == "BackgroundImage") ? slider.Art.Images.First(t => t.Type == "BackgroundImage") : new SkinArtImage();
                    art2 = slider.Art.Images.Any(t => t.Type == "FocusedImage") ? slider.Art.Images.First(t => t.Type == "FocusedImage") : new SkinArtImage();
                    break;
            }
            var img = (BitmapImage) Core.GetImageSourceFromFileName(SkinController.GetFullPath(art.Path));
            var img2 = (BitmapImage) Core.GetImageSourceFromFileName(SkinController.GetFullPath(art2.Path));

            //+ Формирование шаблона контрола
            var xamlGrid = new FrameworkElementFactory(typeof(Grid));
            var xamlBorder = new FrameworkElementFactory(typeof(Border));
            var xamlImage = new FrameworkElementFactory(typeof(Image));
            xamlImage.SetValue(WidthProperty, (double) img.PixelWidth);
            xamlImage.SetValue(HeightProperty, (double) img.PixelHeight);
            xamlImage.SetValue(Image.SourceProperty, img);
            xamlGrid.AppendChild(xamlImage);
            xamlBorder.AppendChild(xamlGrid);
            var xamlImage2 = new FrameworkElementFactory(typeof(Image));
            xamlImage2.SetValue(Image.SourceProperty, img2);
            xamlImage2.SetValue(HorizontalAlignmentProperty, state == SkinButtonState.Clicked ? HorizontalAlignment.Right : HorizontalAlignment.Center);
            xamlImage2.SetValue(WidthProperty, (double) img2.PixelWidth);
            xamlGrid.AppendChild(xamlImage2);
            Template = new ControlTemplate { VisualTree = xamlBorder };
            //- Формирование шаблона контрола
        }
        private void DrawProgressBar(SkinButtonState state)
        {
            var progressBar = (SkinProgressBar) SkinElement;
            var art = new SkinArtImage();
            switch (state) {
                case SkinButtonState.Normal:
                    art = progressBar.Art.Images.Any(t => t.Type == "UnfilledImage") ? progressBar.Art.Images.First(t => t.Type == "UnfilledImage") : new SkinArtImage();
                    break;
                case SkinButtonState.Focused:
                    art = progressBar.Art.Images.Any(t => t.Type == "FilledImage" && !string.IsNullOrEmpty(t.Type))
                        ? progressBar.Art.Images.First(t => t.Type == "FilledImage")
                        : (progressBar.Art.Images.Any(t => t.Type == "UnfilledImage") ? progressBar.Art.Images.First(t => t.Type == "UnfilledImage") : new SkinArtImage());
                    break;
            }
            var img = (BitmapImage) Core.GetImageSourceFromFileName(SkinController.GetFullPath(art.Path));

            //+ Формирование шаблона контрола
            var xamlGrid = new FrameworkElementFactory(typeof(Grid));
            var xamlBorder = new FrameworkElementFactory(typeof(Border));
            var xamlImage = new FrameworkElementFactory(typeof(Image));
            xamlImage.SetValue(WidthProperty, (double) img.PixelWidth);
            xamlImage.SetValue(HeightProperty, (double) img.PixelHeight);
            xamlImage.SetValue(Image.SourceProperty, img);
            xamlGrid.AppendChild(xamlImage);
            xamlBorder.AppendChild(xamlGrid);
            Template = new ControlTemplate { VisualTree = xamlBorder };
            //- Формирование шаблона контрола
        }
        private void DrawButton(SkinButtonState state)
        {
            var button = (SkinButton) SkinElement;
            var art = new SkinArtImage();
            switch (state) {
                case SkinButtonState.Normal:
                    art = button.Art.Images.Any(t => t.Type == "BackgroundImage") ? button.Art.Images.First(t => t.Type == "BackgroundImage") : new SkinArtImage();
                    break;
                case SkinButtonState.Clicked:
                    if (button.Art.Images.Any(t => t.Type == "SelectedImage" && !string.IsNullOrEmpty(t.Type))) {
                        art = button.Art.Images.First(t => t.Type == "SelectedImage");
                    } else {
                        art = button.Art.Images.Any(t => t.Type == "ClickedImage" && !string.IsNullOrEmpty(t.Type))
                            ? button.Art.Images.First(t => t.Type == "ClickedImage")
                            : (button.Art.Images.Any(t => t.Type == "BackgroundImage") ? button.Art.Images.First(t => t.Type == "BackgroundImage") : new SkinArtImage());
                    }
                    break;
                case SkinButtonState.Focused:
                    art = button.Art.Images.Any(t => t.Type == "HoverImage" && !string.IsNullOrEmpty(t.Type))
                        ? button.Art.Images.First(t => t.Type == "HoverImage")
                        : (button.Art.Images.Any(t => t.Type == "BackgroundImage") ? button.Art.Images.First(t => t.Type == "BackgroundImage") : new SkinArtImage());
                    break;
            }
            var img = (BitmapImage) Core.GetImageSourceFromFileName(SkinController.GetFullPath(art.Path));

            //+ Формирование шаблона контрола
            var xamlGrid = new FrameworkElementFactory(typeof(Grid));
            var xamlImage = new FrameworkElementFactory(typeof(Image));
            xamlImage.SetValue(WidthProperty, (double) img.PixelWidth);
            xamlImage.SetValue(HeightProperty, (double) img.PixelHeight);
            xamlImage.SetValue(Image.SourceProperty, img);
            xamlGrid.AppendChild(xamlImage);
            if (!string.IsNullOrEmpty(button.Text)) {
                var xamlTextBlock = new FrameworkElementFactory(typeof(TextBlock));
                xamlTextBlock.SetValue(TextBlock.TextProperty, string.IsNullOrEmpty(button.Text) ? button.Name : button.Text);
                var hAlign = HorizontalAlignment.Center;
                switch (button.Align) {
                    case SkinTextAligh.left: hAlign = HorizontalAlignment.Left; break;
                    case SkinTextAligh.right: hAlign = HorizontalAlignment.Right; break;
                }
                xamlTextBlock.SetValue(HorizontalAlignmentProperty, hAlign);
                xamlTextBlock.SetValue(VerticalAlignmentProperty, VerticalAlignment.Center);
                if (SkinController.SkinApp.Styles.Any(t=>t.Name == button.Style)) {
                    var textStyle = SkinController.SkinApp.Styles.First(t => t.Name == button.Style);
                    xamlTextBlock.SetValue(TextBlock.FontSizeProperty, textStyle.Height);
                    if (textStyle.Weight > 0)
                        xamlTextBlock.SetValue(TextBlock.FontWeightProperty, FontWeight.FromOpenTypeWeight((int) textStyle.Weight));
                    if (Fonts.SystemFontFamilies.Any(t => t.GetTypefaces().Any(f=>f.FaceNames.Any(fn=>fn.Key.ToString().ToLower() == textStyle.Face.ToLower()))))
                        xamlTextBlock.SetValue(TextBlock.FontFamilyProperty, Fonts.SystemFontFamilies.First(t => t.GetTypefaces().Any(f => f.FaceNames.Any(fn => fn.Key.ToString().ToLower() == textStyle.Face.ToLower()))));
                    xamlTextBlock.SetValue(TextBlock.ForegroundProperty, Core.GetColorBrushFromString(textStyle.Default));
                }
                xamlGrid.AppendChild(xamlTextBlock);
            }
            Template = new ControlTemplate { VisualTree = xamlGrid };
            //- Формирование шаблона контрола
        }
        private void DrawComboBox(SkinButtonState state)
        {
            var comboBox = (SkinComboBox) SkinElement;
            var art = new SkinArtImage();
            switch (state) {
                case SkinButtonState.Normal:
                    art = comboBox.Art.Images.Any(t => t.Type == "BackgroundImage") ? comboBox.Art.Images.First(t => t.Type == "BackgroundImage") : new SkinArtImage();
                    break;
                case SkinButtonState.Clicked:
                    if (comboBox.Art.Images.Any(t => t.Type == "SelectedImage" && !string.IsNullOrEmpty(t.Type))) {
                        art = comboBox.Art.Images.First(t => t.Type == "SelectedImage");
                    } else {
                        art = comboBox.Art.Images.Any(t => t.Type == "ClickedImage" && !string.IsNullOrEmpty(t.Type))
                            ? comboBox.Art.Images.First(t => t.Type == "ClickedImage")
                            : (comboBox.Art.Images.Any(t => t.Type == "BackgroundImage") ? comboBox.Art.Images.First(t => t.Type == "BackgroundImage") : new SkinArtImage());
                    }
                    break;
                case SkinButtonState.Focused:
                    art = comboBox.Art.Images.Any(t => t.Type == "HoverImage" && !string.IsNullOrEmpty(t.Type))
                        ? comboBox.Art.Images.First(t => t.Type == "HoverImage")
                        : (comboBox.Art.Images.Any(t => t.Type == "BackgroundImage") ? comboBox.Art.Images.First(t => t.Type == "BackgroundImage") : new SkinArtImage());
                    break;
            }
            var img = (BitmapImage) Core.GetImageSourceFromFileName(SkinController.GetFullPath(art.Path));

            //+ Формирование шаблона контрола
            var xamlGrid = new FrameworkElementFactory(typeof(Grid));
            var xamlBorder = new FrameworkElementFactory(typeof(Border));
            var xamlImage = new FrameworkElementFactory(typeof(Image));
            xamlImage.SetValue(WidthProperty, (double) img.PixelWidth);
            xamlImage.SetValue(HeightProperty, (double) img.PixelHeight);
            xamlImage.SetValue(Image.SourceProperty, img);
            xamlGrid.AppendChild(xamlImage);
            if (!string.IsNullOrEmpty(comboBox.Text)) {
                var xamlTextBlock = new FrameworkElementFactory(typeof(TextBlock));
                xamlTextBlock.SetValue(TextBlock.TextProperty, comboBox.Text);
                xamlTextBlock.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);
                xamlTextBlock.SetValue(VerticalAlignmentProperty, VerticalAlignment.Center);
                if (SkinController.SkinApp.Styles.Any(t => t.Name == comboBox.Style)) {
                    var textStyle = SkinController.SkinApp.Styles.First(t => t.Name == comboBox.Style);
                    xamlTextBlock.SetValue(TextBlock.FontSizeProperty, textStyle.Height);
                    if (textStyle.Weight > 0)
                        xamlTextBlock.SetValue(TextBlock.FontWeightProperty, textStyle.Weight);
                    xamlTextBlock.SetValue(TextBlock.FontFamilyProperty, new FontFamily(textStyle.Face));
                    xamlTextBlock.SetValue(TextBlock.ForegroundProperty, Core.GetColorBrushFromString(textStyle.Default));
                }
                xamlGrid.AppendChild(xamlTextBlock);
            }
            xamlBorder.AppendChild(xamlGrid);
            Template = new ControlTemplate { VisualTree = xamlBorder };
            //- Формирование шаблона контрола
        }
        private void RebuildImageMap(SkinArtImage artBgMap, SkinElement element)
        {
            element.ColorPositions.Clear();

            var imageMap = (BitmapImage) Core.GetImageSourceFromFileName(GetFullPath(artBgMap.Path));
            var bmp = Core.BitmapImage2Bitmap(imageMap);

            var transparentColor = bmp.GetPixel(0, 0);
            AppProgressBarController.SetValue(0, bmp.Height, "Analyzing image map...");
            AppProgressBarController.Show();
            var i = 0;
            for (var y = 0; y < imageMap.PixelHeight; y++) {
                i++;
                if (i%10 == 0) {
                    AppProgressBarController.SetValue(i, bmp.Height, "Analyzing image map...");
                    AppProgressBarController.DoEvents();
                }
                for (var x = 0; x < imageMap.PixelWidth; x++) {
                    //  Получаем цвет фона карты
                    var pixel = bmp.GetPixel(x, y);
                    if (x == 0 && y == 0) {
                        transparentColor = Color.FromArgb(pixel.A, pixel.R, pixel.G, pixel.B);
                        continue;
                    }
                    var currentPixelColor = Color.FromArgb(pixel.A, pixel.R, pixel.G, pixel.B);
                    if (currentPixelColor != transparentColor) {
                        if (element.ColorPositions.Any(t => t.MapColor == currentPixelColor)) {
                            var pos = element.ColorPositions.First(t => t.MapColor == currentPixelColor);
                            pos.Width = x > pos.X + pos.Width - 1 ? x - pos.X + 1 : pos.Width;
                            pos.Height = y > pos.Y + pos.Height - 1 ? y - pos.Y + 1 : pos.Height;
                        } else {
                            element.ColorPositions.Add(new ColorPosition { MapColor = currentPixelColor, X = x, Y = y });
                        }
                    }
                }
            }
            AppProgressBarController.Hide();
        }