改变wpf上的关键点的状态的代码如下:
public SearchWindow()
{
this.InitializeComponent();
//----------------------------动态brush示例---------------------------
//Brush br_en = this.FindResource("Brush_province_enable") as Brush;
//Path pp = this.FindName("point_shandong") as Path;
//pp.Fill = br_en;
//----------------------------动态brush示例完毕---------------------------
//---------------------遍历ping table,改变点的状态--------------------------
Brush br_en = this.FindResource("Brush_province_enable") as Brush;
Brush br_dis = this.FindResource("Brush_province_disable") as Brush;
webscanTableAdapters.PINGTableAdapter da = new webscanTableAdapters.PINGTableAdapter();
webscan.PINGDataTable pt = da.GetData();
string point_name, point_brush, storyboard_name,tooltip_target_name;
Path pp;
FrameworkElement tooltip_target;
Storyboard my_sb;
foreach (DataRow myRow in pt.Rows)
{
point_name = myRow["point_name"].ToString();
point_brush = myRow["point_brush"].ToString();
storyboard_name = myRow["STORYBOARD"].ToString();
tooltip_target_name = myRow["TOOLTIP_TARGET"].ToString();
pp = this.FindName(point_name) as Path;
tooltip_target = (FrameworkElement)this.FindName(tooltip_target_name);
//------------------------------点的颜色-------------------------
try
{
pp.Fill = (Brush)this.FindResource(point_brush);
}
catch { }
//------------------------------storyboard-------------------------
try
{
my_sb = (Storyboard)this.FindResource(storyboard_name);
if (myRow["remark"].ToString() == "关闭")
my_sb.Begin(this);
}
catch { }
//-------------------------tooltip------------------------
try
{
tooltip_target.ToolTip = GetToolTip(myRow["name"].ToString(),myRow["remark"].ToString());
}
catch { }
}
//---------------------遍历ping table,改变点的状态--------------------------
// Insert code required on object creation below this point.
EventManager.RegisterClassHandler(typeof(SearchBox), SearchBox.SearchEvent, new RoutedEventHandler(this.OnSearch));
EventManager.RegisterClassHandler(typeof(SearchWindow), SearchWindow.CloseSearchResult, new RoutedEventHandler(this.OnCloseSearchResult));
this.searchResultModel = (SearchResultModel)((ObjectDataProvider)this.Resources["SearchResultModelDS"]).Data;
}
private ToolTip GetToolTip(string name, string remark)
{
StackPanel sp = new StackPanel();
Label lb = new Label();
lb.FontWeight = FontWeights.Bold;
lb.Background = Brushes.Blue;
lb.Foreground = Brushes.White;
lb.Content = name+"检测结果";
sp.Children.Add(lb);
TextBlock tb = new TextBlock();
tb.Padding = new Thickness(10);
tb.TextWrapping = TextWrapping.WrapWithOverflow;
tb.Width = 200;
tb.Text = name + "\r" + remark;
sp.Children.Add(tb);
Line ln = new Line();
ln.Stroke = Brushes.Black;
ln.StrokeThickness = 1;
ln.X2 = 200;
sp.Children.Add(ln);
StackPanel sp2 = new StackPanel();
sp2.Orientation = Orientation.Horizontal;
//----