I've a method that when called returns a LinearGradientBrush with random color for the GradientStop and I use on them mylabel.RegisterName for later use in a storyboard animation.
To prevent the error on first call where no registered name are present I do this:
try
{
myLabel.UnregisterName("GS1");
myLabel.UnregisterName("GS2");
myLabel.UnregisterName("GS3");
myLabel.UnregisterName("GS4");
}
catch
{
}
I have not found a way to overwrite registered name. There's a better way to do this?
What about UnregisterName?
(That's what I get for attempting to answer when I can only read part of the question...)
Digging around a bit more, may have found another (WAY simpler) alternative:
var isGs1Defined = NameScope.GetNameScope(myLabel).FindName("GS1") == null;
or packaged up nicely:
public static bool IsNameRegistered(DependencyObject depObject, string name)
{
var namescope = NameScope.GetNameScope(depObject);
if(namescope == null)
return false;
return namescope.FindName(name) != null;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With