WPF 中的相关样式
阅读原文时间:2023年07月11日阅读:1

           

                                       

Label 设置背景色

Label.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#626363"));
Label.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#626363"));

设置背景图片

//tabA1.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri(filepath)) };

画图形顺序为逆时针



                    </Polygon.Fill>  
                </Polygon>

后台修改所画的图形位置

private void Removestate(Polygon path, TextBlock label)
{
if (path.Points[0].Y == 0)
{
path.Points[0] = new Point(path.Points[0].X + 10, path.Points[0].Y + 10);
path.Points[1] = new Point(path.Points[1].X + 10, path.Points[1].Y + 10);
path.Points[2] = new Point(path.Points[2].X + 10, path.Points[2].Y + 10);
path.Points[3] = new Point(path.Points[3].X + 10, path.Points[3].Y + 10);
Canvas.SetTop(label, Canvas.GetTop(label) + 10);
Canvas.SetLeft(label, Canvas.GetLeft(label) + 10);
path.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#547EAD"));
}

    }

Image 绑定

image1.Source = new BitmapImage(new Uri(filepath + "Resources\\images\\map2.png"));

RichTextBox定时刷新添加内容

delegate void mydelete();
private void bindRichText()
{
try
{
DispatcherTimer dTimer = new System.Windows.Threading.DispatcherTimer();

            dTimer.Tick += new EventHandler(dTimer\_Tick);  
            dTimer.Interval = new TimeSpan(0, 0, 0, 0, 1000);

            string filepath = Environment.CurrentDirectory;  
            if (filepath.Substring(filepath.Length - 1) != "/")  
                filepath += "\\\\" + "DataFile\\\\" + "rich1.txt";  
            StreamReader sr = new StreamReader(filepath, Encoding.Default);  
            allinfo = new List<string>();  
            string rowinfo = "";  
            while (!string.IsNullOrEmpty(rowinfo = sr.ReadLine()))  
            {  
                allinfo.Add(rowinfo);  
            }  
            sr.Close();  
            sr.Dispose();  
            setText();  
            dTimer.Start();  
        }  
        catch (Exception ex)  
        {  
            MessageBox.Show(ex.Message);  
        }  
    }  
    void dTimer\_Tick(object sender, EventArgs e)  
    {  
        try  
        {  
            mydelete dele = new mydelete(setText);  
            dele.Invoke();  
        }  
        catch (Exception ex)  
        {  
            MessageBox.Show(ex.Message);  
        }  
    }

    private void setText()  
    {  
        if (i == allinfo.Count - 1)  
            i = 0;  
        this.richTextmain.AppendText(allinfo\[i\] + "\\r");  
        this.richTextMemo.ScrollToEnd();  
        i++;  
    }

Frame 绑定

string filepath = Environment.CurrentDirectory;
if (filepath.Substring(filepath.Length - 1) != "/")
filepath += "\\" + "MyHtml\\sdf.htm";
frame.Source = new Uri(filepath);

后台画路径/图形

void dTimer1_Tick(object sender, EventArgs e)
{
Random dr = new Random();
string varchar = chartData[dr.Next(0, chartData.Length)];
Thread.Sleep(1000);
if (varchar != null && varchar != "")
{
string[] v = varchar.Split(',');
Point p1 = new Point(Convert.ToInt32(v[0]), Convert.ToInt32(v[1]));
Point p2 = new Point(Convert.ToInt32(v[2]), Convert.ToInt32(v[3]));
Point p3 = new Point(Convert.ToInt32(v[4]), Convert.ToInt32(v[5]));
Point p4 = new Point(Convert.ToInt32(v[6]), Convert.ToInt32(v[7]));
Point[] values = new Point[] { p1, p2, p3, p4 };
StreamGeometry theGeometry = BuildRegularPolygon(values, true, true);
path1.Data = theGeometry;
}
}

WPF DataGrid