I have a wpf setup where I have a timer running and I want to check to see what services are running and their state. I had this working in .net 4.5 but when I rolled it back to 4 the dispatcher signature changed and I am no longer able to access the elements. Basically I have The dispatcher object makes a call to the methods GetElementName
//use dispatcher to execute on the UI thread vs timer thread
Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { GetElementName(0, s.LabelName); }));
Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { GetElementName(1, s.LabelName); }));
Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { GetElementName(2, s.LabelName); }));
GetElementName(int, string) basically evaluates the type and name and is supposed to locate the element within the UI.
private void GetElementName(int etype, string labelName)
{
switch (etype)
{
case 0:
CurrentLabel = (Label)base.FindName(labelName);
break;
case 1:
CurrentGrid = (Grid)base.FindName(labelName);
break;
case 2:
CurrentEllipse = (Ellipse)base.FindName(labelName);
break;
}
}
//dummy properties
public Label CurrentLabel { get; set; }
public Grid CurrentGrid { get; set; }
public Ellipse CurrentEllipse { get; set; }
What I am seeing is the properties never get set they always return null.
Any suggestions on what I am missing here as to why the items are not being located and set?
This is a really simple/basic app so I am not overlaying any pattern this is straight code-behind from the Main-Window.xaml file. Each element that I want to modify has a x:Name identifier.
Edit
In bypassing the select statement I have also explicitly written out the attempt to retrieve the UI element using the following:
CurrentLabel = (Label)Dispatcher.Invoke((Action)(() => { FindName(s.LabelName); }));
CurrentGrid = (Grid)Dispatcher.Invoke((Action)(() => { FindName(s.GridName); }));
CurrentEllipse = (Ellipse)Dispatcher.Invoke((Action)(() => { FindName(s.ElipseName); }));
This has also returned null values
-cheers,