public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            DataTemplate dt = new DataTemplate();

            if (item != null && item is Context)
            {
                BaseInfoType model  = (item as Context).info;
                Window       window = Application.Current.MainWindow;
                if (model.GetInfoType().Equals(BaseInfoType.InfoType.LiteralText))
                {
                    //实例化标签控件
                    FrameworkElementFactory txtBox = new FrameworkElementFactory(typeof(TextBox));
                    txtBox.SetBinding(TextBox.TextProperty, new Binding()
                    {
                        Path = new PropertyPath("Content"),
                        Mode = BindingMode.TwoWay,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                    });
                    txtBox.SetValue(TextBox.ForegroundProperty, Brushes.Black);
                    txtBox.SetValue(TextBox.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
                    dt.VisualTree = txtBox;
                }
                else if (model.GetInfoType().Equals(BaseInfoType.InfoType.Picture))
                {
                    //实例化图像框控件
                    FrameworkElementFactory image = new FrameworkElementFactory(typeof(Image));
                    image.SetBinding(Image.SourceProperty, new Binding()
                    {
                        Path = new PropertyPath("Source"),
                        Mode = BindingMode.TwoWay,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                    });
                    image.SetValue(Image.StretchProperty, Stretch.Uniform);
                    dt.VisualTree = image;
                }
                else
                {
                    //实例化文本控件
                    FrameworkElementFactory txtBox = new FrameworkElementFactory(typeof(TextBox));
                    txtBox.SetBinding(TextBox.TextProperty, new Binding()
                    {
                        Path = new PropertyPath("Content"),
                        Mode = BindingMode.TwoWay,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                    });
                    txtBox.SetValue(TextBox.ForegroundProperty, Brushes.White);
                    txtBox.SetValue(TextBox.BackgroundProperty, new SolidColorBrush(Colors.Transparent));
                    dt.VisualTree = txtBox;
                }
            }
            return(dt);
        }
Пример #2
0
        public Context(BaseInfoType con)
        {
            this.info    = con;
            this.Name    = this.info.Name;
            this.Content = this.info.ToString();
            if (con.GetInfoType().Equals(BaseInfoType.InfoType.Picture))
            {
                ms = new MemoryStream(con.Data);

                ImageBrush           imageBrush           = new ImageBrush();
                ImageSourceConverter imageSourceConverter = new ImageSourceConverter();

                this.Source = (ImageSource)imageSourceConverter.ConvertFrom(ms);
                //ms.Close();
            }
        }
Пример #3
0
 public BaseInfo(BaseInfoType type)
 {
     Type = type;
 }
Пример #4
0
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            DataTemplate dt = new DataTemplate();

            if (item != null && item is Context)
            {
                BaseInfoType model  = (item as Context).info;
                MainWindow   window = (MainWindow)Application.Current.MainWindow;
                if (model.GetInfoType().Equals(BaseInfoType.InfoType.LiteralText))
                {
                    //实例化标签控件
                    FrameworkElementFactory label = new FrameworkElementFactory(typeof(Label));
                    label.SetBinding(Label.ContentProperty, new Binding()
                    {
                        Path = new PropertyPath("Content"),
                        Mode = BindingMode.TwoWay,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                    });
                    label.SetValue(Label.ForegroundProperty, Brushes.Black);
                    label.SetValue(Label.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                    TextBlock tb = new TextBlock();
                    ToolTip   tt = new ToolTip();
                    tb              = new TextBlock();
                    tb.MaxWidth     = 700;
                    tb.TextWrapping = TextWrapping.Wrap;
                    tt.Content      = tb;
                    label.SetValue(Label.ToolTipProperty, tt);
                    label.AddHandler(UIElement.MouseMoveEvent, new MouseEventHandler(TemplateLabelEventHandlers.label_MouseMove));
                    label.AddHandler(UIElement.MouseLeaveEvent, new MouseEventHandler(TemplateLabelEventHandlers.label_MouseLeave));
                    dt.VisualTree = label;
                }
                else if (model.GetInfoType().Equals(BaseInfoType.InfoType.Picture))
                {
                    //实例化图像框控件
                    FrameworkElementFactory image = new FrameworkElementFactory(typeof(Image));
                    image.SetBinding(Image.SourceProperty, new Binding()
                    {
                        Path = new PropertyPath("Source"),
                        Mode = BindingMode.TwoWay,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                    });
                    Image im = new Image();
                    im.MaxWidth  = 700;
                    im.MaxHeight = 700;
                    im.Stretch   = Stretch.Uniform;
                    im.SetBinding(Image.SourceProperty, new Binding()
                    {
                        Path = new PropertyPath("Source"),
                        Mode = BindingMode.TwoWay,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                    });
                    ToolTip tt = new ToolTip();
                    tt.Content = im;
                    image.SetValue(Image.ToolTipProperty, tt);
                    image.AddHandler(Image.ToolTipClosingEvent, new ToolTipEventHandler(TemplateImageEventHandlers.toolTip_Closing));
                    image.SetValue(Image.StretchProperty, Stretch.Uniform);
                    dt.VisualTree = image;
                }
                else
                {
                    //实例化文本控件
                    FrameworkElementFactory txtBox = new FrameworkElementFactory(typeof(TextBox));
                    txtBox.SetBinding(TextBox.TextProperty, new Binding()
                    {
                        Path = new PropertyPath("Content"),
                        Mode = BindingMode.TwoWay,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                    });
                    txtBox.SetValue(TextBox.ForegroundProperty, Brushes.White);
                    txtBox.SetValue(TextBox.BackgroundProperty, new SolidColorBrush(Colors.Transparent));
                    dt.VisualTree = txtBox;
                }
            }
            return(dt);
        }