Exemple #1
0
        private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            AyImage bitmap = (AyImage)d;

            BitmapSource oldValue = (BitmapSource)e.OldValue;
            BitmapSource newValue = (BitmapSource)e.NewValue;

            if (((oldValue != null) && (bitmap._sourceDownloaded != null)) && (!oldValue.IsFrozen && (oldValue is BitmapSource)))
            {
                ((BitmapSource)oldValue).DownloadCompleted -= bitmap._sourceDownloaded;
                ((BitmapSource)oldValue).DownloadFailed    -= bitmap._sourceFailed;
                // ((BitmapSource)newValue).DecodeFailed -= bitmap._sourceFailed; // 3.5
            }
            if (((newValue != null) && (newValue is BitmapSource)) && !newValue.IsFrozen)
            {
                ((BitmapSource)newValue).DownloadCompleted += bitmap._sourceDownloaded;
                ((BitmapSource)newValue).DownloadFailed    += bitmap._sourceFailed;
                // ((BitmapSource)newValue).DecodeFailed += bitmap._sourceFailed; // 3.5
            }
        }
Exemple #2
0
        public void LoadIcon()
        {
            //判断Icon方式
            if (!string.IsNullOrEmpty(Icon))
            {
                string ext = System.IO.Path.GetExtension(Icon);
                if (ext == "")
                {
                    //<control:AyStrokeLabel Text="&#xf007;" Style="{StaticResource FontAwesome}" Fill="Yellow" Stroke="Black" StrokeThickness="0.3" FontWeight="Bold" FontSize="50"/>
                    if (Icon.IndexOf("fa_") == 0 || Icon.IndexOf("fa-") == 0)
                    {
                        if (IsFontStrokeLabel)
                        {
                            tb = new AyStrokeLabel
                            {
                                VerticalAlignment = VerticalAlignment.Center,
                                Stroke            = Stroke,
                                StrokeThickness   = StrokeThickness,
                                FontWeight        = FontWeight,
                                FontStretch       = FontStretch,
                                FontStyle         = FontStyle,
                                UseLayoutRounding = true
                            };
                            Binding bindingFont = new Binding {
                                Path = new PropertyPath("FontSize"), Source = this, Mode = BindingMode.TwoWay
                            };
                            tblock.SetBinding(TextBlock.FontSizeProperty, bindingFont);
                            //设置绑定
                            Binding binding = new Binding {
                                Path = new PropertyPath("Foreground"), Source = this, Mode = BindingMode.TwoWay
                            };
                            tb.SetBinding(AyStrokeLabel.FillProperty, binding);

                            tb.Style = Application.Current.TryFindResource("FontAwesome") as Style;
                            Icon     = Icon.Replace(" ", "").Replace("-", "_");
                            tb.Text  = FontAweSomeHelper.GetUnicode(Icon);
                            //tb.Text = "&#xf1b9;";
                            this.Content = tb;
                        }
                        else
                        {
                            tblock = new TextBlock
                            {
                                VerticalAlignment = VerticalAlignment.Center,
                                FontWeight        = FontWeight,
                                FontStretch       = FontStretch,
                                FontStyle         = FontStyle,
                                UseLayoutRounding = true
                            };
                            Binding bindingFont = new Binding {
                                Path = new PropertyPath("FontSize"), Source = this, Mode = BindingMode.TwoWay
                            };
                            tblock.SetBinding(TextBlock.FontSizeProperty, bindingFont);
                            //设置绑定
                            Binding binding = new Binding {
                                Path = new PropertyPath("Foreground"), Source = this, Mode = BindingMode.TwoWay
                            };
                            tblock.SetBinding(TextBlock.ForegroundProperty, binding);

                            tblock.Style = Application.Current.TryFindResource("FontAwesome") as Style;
                            Icon         = Icon.Replace(" ", "").Replace("-", "_");
                            tblock.Text  = FontAweSomeHelper.GetUnicode(Icon);
                            this.Content = tblock;
                        }

                        IconType = AyIconAllType.Font;
                    }
                    else if (Icon.IndexOf("path_") == 0)
                    {
                        //2015-5-27 16:57:15   联系qq 875556003   更新,改为性能更好的path
                        btn1 = new AyPath
                        {
                            SnapsToDevicePixels = true,
                            VerticalAlignment   = VerticalAlignment.Stretch,
                            HorizontalAlignment = HorizontalAlignment.Stretch,
                            //PathStrokeBrush = Stroke,
                            //Foreground=Foreground,
                            //PathStrokeThickness = StrokeThickness,
                            Stretch           = Stretch,
                            UseLayoutRounding = true
                        };
                        PathIcon.SetIcon(btn1, Icon);
                        //设置绑定
                        Binding binding = new Binding {
                            Path = new PropertyPath("Foreground"), Source = this, Mode = BindingMode.TwoWay
                        };
                        btn1.SetBinding(AyPath.ForegroundProperty, binding);

                        Binding binding2 = new Binding {
                            Path = new PropertyPath("Stroke"), Source = this, Mode = BindingMode.TwoWay
                        };
                        btn1.SetBinding(AyPath.PathStrokeBrushProperty, binding2);

                        Binding binding3 = new Binding {
                            Path = new PropertyPath("StrokeThickness"), Source = this, Mode = BindingMode.TwoWay
                        };
                        btn1.SetBinding(AyPath.PathStrokeThicknessProperty, binding3);


                        this.Content = btn1;
                        IconType     = AyIconAllType.Path;
                    }
                    else if (Icon.IndexOf("more_") == 0)
                    {
                        this.Content = GetMoreIcon();
                        IconType     = AyIconAllType.More;
                    }
                }
                else if (ext == ".gif")
                {
                    try
                    {
                        imageGif = new AyGifControl
                        {
                            Width               = this.Width,
                            Height              = this.Height,
                            VerticalAlignment   = VerticalAlignment.Stretch,
                            HorizontalAlignment = HorizontalAlignment.Stretch,
                            Stretch             = ImageStretch
                        };
                        imageGif.InitControl(Icon);
                        imageGif.StartAnimate();
                        this.Content = imageGif;
                        IconType     = AyIconAllType.Gif;
                    }
                    catch
                    {
                        //AyMessageBox.ShowError(ex.Message);
                    }
                }
                else
                {
                    try
                    {
                        if (IsBitmapImage)
                        {
                            AyImage image = new AyImage();
                            this.IsBitmapImage = false;
                            if (Icon.IndexOf("pack://") == 0)
                            {
                            }
                            image.Source = new BitmapImage(new Uri(Icon, UriKind.RelativeOrAbsolute));
                            this.Content = image;
                        }
                        else
                        {
                            Image image = new Image
                            {
                                VerticalAlignment   = VerticalAlignment.Stretch,
                                HorizontalAlignment = HorizontalAlignment.Stretch,
                                Stretch             = ImageStretch
                            };
                            image.UseLayoutRounding = true;
                            if (Icon.IndexOf("pack://") == 0)
                            {
                            }
                            image.Source = new BitmapImage(new Uri(Icon, UriKind.RelativeOrAbsolute));
                            this.Content = image;
                        }
                        IconType = AyIconAllType.Image;
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("文件格式不正确" + ex.Message);
                    }
                }
            }
        }