Beispiel #1
0
        //姜彦 20180112 21:23
        //string strPId1 = string.Empty;  //全局变量  为了传递cell的变化内容,上一个跟下一个对比的传递媒介
        //static BrushConverter conv1 = new BrushConverter();
        //Brush color0;//通过第三个值  交换颜色 原理 A B C 通过C 交换A B
        //Brush color1 = conv1.ConvertFromInvariantString("#E2E9E1") as Brush;//浅绿色EECEE0
        //Brush color2 = conv1.ConvertFromInvariantString("#FFFFFF") as Brush;//白色
        private void dgFormula_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            //var obj1 = e.Row.DataContext;
            //var vM = obj1 as TFormulaViewModel;
            //if (strPId1 == vM.StrId)
            //{
            //    e.Row.Background = (System.Windows.Media.Brush)color1;//浅绿色
            //}
            //else
            //{
            //    e.Row.Background = (System.Windows.Media.Brush)color2;//白色
            //    color0 = color1;//通过第三个值  交换颜色 原理 A B C 通过C 交换A B
            //    color1 = color2;
            //    color2 = color0;
            //}
            //strPId1 = vM.StrId;

            BrushConverter conv1  = new BrushConverter();
            Brush          color1 = conv1.ConvertFromInvariantString("#E2E9E1") as Brush; //浅绿色EECEE0
            Brush          color2 = conv1.ConvertFromInvariantString("#FFFFFF") as Brush; //白色

            var obj1 = e.Row.DataContext;
            var vM   = obj1 as TFormulaViewModel;

            if (vM.ColorFlag)
            {
                e.Row.Background = (System.Windows.Media.Brush)color1;//浅绿色
            }
            else
            {
                e.Row.Background = (System.Windows.Media.Brush)color2;//白色
            }
        }
        private void SetBtnColor(Button btn, string color)
        {
            BrushConverter conv = new BrushConverter();
            Brush          bru  = conv.ConvertFromInvariantString(color) as Brush;

            btn.Background = (System.Windows.Media.Brush)bru;
        }
Beispiel #3
0
        /// <summary>
        /// 初始化记得密码
        /// </summary>
        private void InitRemeber()
        {
            LoginViewModel view = new LoginViewModel();

            view.ReadConfigInfo(); //读写配置参数
            this.DataContext = view;
            if (view.UserLogin)
            {
                view.Login();
            }
            if (view.Password == "")
            {
                BrushConverter conv = new BrushConverter();
                Brush          bru  = conv.ConvertFromInvariantString("#FFCDC78A") as Brush;
                BtnLogin.Background = (Brush)bru;

                BrushConverter conv1 = new BrushConverter();
                Brush          bru1  = conv1.ConvertFromInvariantString("#FF6A6262") as Brush;
                BtnLogin.Foreground = (Brush)bru1;
                BtnLogin.Cursor     = Cursors.Arrow;
                BtnLogin.IsEnabled  = false;
            }
            else
            {
                BrushConverter conv = new BrushConverter();
                Brush          bru  = conv.ConvertFromInvariantString("#FFEEE052") as Brush;
                BtnLogin.Background = (Brush)bru;
                BtnLogin.Foreground = Brushes.Black;
                BtnLogin.Cursor     = Cursors.Hand;
                BtnLogin.IsEnabled  = true;
            }
        }
Beispiel #4
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(new SolidColorBrush(Colors.Black));
            }

            BrushConverter bc = new BrushConverter();

            return(bc.ConvertFromInvariantString((String)value));
        }
Beispiel #5
0
        //  static readonly ILog _log = LogManager.GetLogger(typeof(ItemIndexMatchToBrush));
        //if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); }
        //if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); }

        #region IMultiValueConverter Members

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //1st value is item.
            //2nd is selectedindex
            //3rd is collection
            //parm is color on match | color on no match.
            Brush retVal = null;

            if (values != null)
            {
                if (parameter != null)
                {
                    string[] parms = parameter.ToString().Split('|');
                    if (parms.Length >= 2)
                    {
                        BrushConverter cnv = new BrushConverter();

                        Brush colorOnMatch   = cnv.ConvertFromInvariantString(parms[0]) as Brush;
                        Brush colorOnNomatch = cnv.ConvertFromInvariantString(parms[1]) as Brush;
                        if (colorOnMatch != null && colorOnNomatch != null)
                        {
                            if (values.Length >= 3)
                            {
                                IList collection    = values[2] as IList;
                                int   selectedIndex = (int)values[1];
                                if (collection != null && collection.IndexOf(values[0]) == selectedIndex)
                                {
                                    retVal = colorOnMatch;
                                }
                                else
                                {
                                    retVal = colorOnNomatch;
                                }
                            }
                        }
                    }
                }
            }
            return(retVal);
        }
Beispiel #6
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     if (value is string)
     {
         var brush = BrushConverter.ConvertFromInvariantString((string)value) as Brush;
         if (brush != null)
         {
             var pen = new Pen(brush, 1);
             pen.Freeze();
             return(pen);
         }
     }
     return(base.ConvertFrom(context, culture, value));
 }
Beispiel #7
0
        //static readonly ILog _log = LogManager.GetLogger(typeof(ValidationToBrush));
        //if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); }
        //if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); }

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //parameter = "propertyMatch|Color If success|Color if Warning|Color if Error
            Brush retVal = null;
            ValidationObjectCollection validation = null;

            if (value != null)
            {
                validation = value as ValidationObjectCollection;

                if (parameter != null)
                {
                    string[]         parms          = parameter.ToString().Split('|');
                    string           key            = parms[0];
                    ValidationObject val            = validation.GetValidationResult(key);
                    string           colorOnSuccess = parms[1];
                    string           colorOnWarn    = parms[2];
                    string           colorOnError   = parms[3];
                    BrushConverter   cnv            = new BrushConverter();
                    switch (val.Code)
                    {
                    case ValidationValue.IsValid:
                        retVal = cnv.ConvertFromInvariantString(colorOnSuccess) as Brush;
                        break;

                    case ValidationValue.IsWarnState:
                        retVal = cnv.ConvertFromInvariantString(colorOnWarn) as Brush;
                        break;

                    case ValidationValue.IsError:
                        retVal = cnv.ConvertFromInvariantString(colorOnError) as Brush;
                        break;
                    }
                }
            }
            return(retVal);
        }
Beispiel #8
0
        static Brush GetCachedBrush(string color)
        {
            Brush brush;

            if (!brushes.TryGetValue(color, out brush))
            {
                try
                {
                    brush = (Brush)converter.ConvertFromInvariantString(color);
                    brush.Freeze();
                }
                catch (FormatException)
                {
                    brush = Brushes.Black;
                }
            }
            return(brush);
        }
        public static Brush GetBrush(string color)
        {
            Brush brush;

            if (!myBrushes.TryGetValue(color, out brush))
            {
                try
                {
                    if (color.Equals("lightgrey", StringComparison.OrdinalIgnoreCase))
                    {
                        color = "LightGray";
                    }

                    brush = ( Brush )myBrushConverter.ConvertFromInvariantString(color);
                    brush.Freeze();
                }
                catch (FormatException)
                {
                    brush = Brushes.Black;
                }
            }
            return(brush);
        }
Beispiel #10
0
        private void PwdTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            if (PwdTextBox.Text != "")
            {
                BrushConverter conv = new BrushConverter();
                Brush          bru  = conv.ConvertFromInvariantString("#FFEEE052") as Brush;
                BtnLogin.Background = (Brush)bru;
                BtnLogin.Foreground = Brushes.Black;
                BtnLogin.Cursor     = Cursors.Hand;
                BtnLogin.IsEnabled  = true;
            }
            else
            {
                BrushConverter conv = new BrushConverter();
                Brush          bru  = conv.ConvertFromInvariantString("#FFCDC78A") as Brush;
                BtnLogin.Background = (Brush)bru;

                BrushConverter conv1 = new BrushConverter();
                Brush          bru1  = conv1.ConvertFromInvariantString("#FF6A6262") as Brush;
                BtnLogin.Foreground = (Brush)bru1;
                BtnLogin.Cursor     = Cursors.Arrow;
                BtnLogin.IsEnabled  = false;
            }
        }
        public void mystart()
        {
            //rtb_detail.Width = tb_detail.Width;

            //TextBlock tb = new TextBlock();
            //tb.Text= "hello!hello!hello!hello!hello!hello!hello!hello!";
            //double w1=tb.Width;

            //TextBox tb_hide = new TextBox();
            //tb_hide.Text = "hello!hello!hello!hello!hello!hello!hello!hello!";
            //double w = tb_hide.Width;

            //Grid 表格,用于留言详情的布局
            Grid grid_messageDetail_buyer = new Grid();

            grid_messageDetail_buyer.Margin = new Thickness(10, 2, 80, 2);

            RowDefinition rd_messageDetail_buyer1 = new RowDefinition();
            RowDefinition rd_messageDetail_buyer2 = new RowDefinition();

            grid_messageDetail_buyer.RowDefinitions.Add(rd_messageDetail_buyer1);
            grid_messageDetail_buyer.RowDefinitions.Add(rd_messageDetail_buyer2);
            ColumnDefinition cd_messageDetail_buyer = new ColumnDefinition();

            grid_messageDetail_buyer.ColumnDefinitions.Add(cd_messageDetail_buyer);

            //TextBlock 发送者姓名和时间
            TextBlock tb_buyer = new TextBlock();

            tb_buyer.Text = "Gary Tang | 2017-12-07 15:03:22";
            BrushConverter bc  = new BrushConverter();
            Brush          bru = bc.ConvertFromInvariantString("#666666") as Brush;

            tb_buyer.Foreground = bru;
            Grid.SetRow(tb_buyer, 0);

            grid_messageDetail_buyer.Children.Add(tb_buyer);

            //StackPanel 用于建立信息气泡,限定文字的范围
            StackPanel sp_messageBox = new StackPanel();

            Grid.SetRow(sp_messageBox, 1);
            Image img_point = new Image();

            img_point.Source              = new BitmapImage(new Uri("/Resources/Images/BubblePoint_gray.png", UriKind.Relative));
            img_point.Width               = 10;
            img_point.Margin              = new Thickness(20, 0, 0, 0);
            img_point.VerticalAlignment   = VerticalAlignment.Bottom;
            img_point.HorizontalAlignment = HorizontalAlignment.Left;
            sp_messageBox.Children.Add(img_point);

            //StackPanel 用于使富文本编辑框自适应尺寸
            StackPanel sp_messageDetail = new StackPanel();

            sp_messageDetail.Orientation = Orientation.Horizontal;

            //RichTextBox富文本编辑框
            AutoSizeRichTextBox rtb_messageDetail = new AutoSizeRichTextBox();

            rtb_messageDetail.IsReadOnly    = true;
            rtb_messageDetail.AcceptsReturn = true;
            //通过隐藏的textbox来获取宽度。
            //TextBox tb_hide = new TextBox();
            //tb_hide.MaxWidth = 800;

            //rtb_messageDetail.MinWidth = 50;
            //rtb_messageDetail.MaxWidth = 500;
            BrushConverter bc_gray  = new BrushConverter();
            Brush          bru_gray = bc_gray.ConvertFromInvariantString("#e6e6e6") as Brush;

            rtb_messageDetail.BorderBrush = bru_gray;
            rtb_messageDetail.Background  = bru_gray;
            BrushConverter bc_white  = new BrushConverter();
            Brush          bru_white = bc_white.ConvertFromInvariantString("#000000") as Brush;

            rtb_messageDetail.Foreground = bru_white;



            //富文本编辑框内的文字内容和图片
            string       detailText = "hello!hello!hello!hello!hello!hello!hello!hello!";
            FlowDocument doc        = new FlowDocument();
            Paragraph    p          = new Paragraph();
            Run          r1         = new Run(detailText);
            Run          r2         = new Run(detailText);

            //图片
            Image       img  = new Image();
            BitmapImage bImg = new BitmapImage();

            bImg.BeginInit();
            bImg.UriSource = new Uri("img_bg.png", UriKind.Relative);
            bImg.EndInit();
            img.Source = bImg;
            img.Width  = 50;
            InlineUIContainer il_img = new InlineUIContainer(img);

            p.Inlines.Add(r1);//Run级元素添加到Paragraph元素的Inline
            p.Inlines.Add(il_img);
            p.Inlines.Add(r2);
            doc.Blocks.Add(p);//Paragraph级元素添加到流文档的块级元素
            rtb_messageDetail.Document = doc;
            Image message_image = new Image();

            message_image.Source = new BitmapImage(new Uri("http://ae01.alicdn.com/kf/HTB1u.UKa7fb_uJkSnfoq6z_epXar.jpg"));

            InlineUIContainer container = new InlineUIContainer(message_image);
            Paragraph         paragraph = new Paragraph(container);

            rtb_messageDetail.Document.Blocks.Add(paragraph);
            //rtb_messageDetail.Document.Blocks.Add(p);

            sp_messageDetail.Children.Add(rtb_messageDetail);

            sp_messageBox.Children.Add(sp_messageDetail);

            grid_messageDetail_buyer.Children.Add(sp_messageBox);

            sp_messageDetail_outside.Children.Add(grid_messageDetail_buyer);
        }