Social Icons

twitter google plus linkedin rss feed

Pages

9.11.10

Changing the NewValue in the PropertyChangedCallback

I don't usually write about Silverlight, this is for two main reasons, first because there's a lot of information in a lot of blogs and second because I don't work that much with Silverlight so I don't find that much problems. It was perfect until I really knew it, same as many other things...


Lately I'm using a lot this technology so new to me and already outdated for Microsoft and doubts are arising i.e. the one in today's post.

I was creating a new button to add it to a DataGrid as a DataGridTemplateColumn and I needed to create a DependencyProperty to bind it, everything very straightforward so far, but in the last moment when I was seen myself victorious I found a problem. If the property (an URL in this case) is not valid, How can I change the NewValue in the PropertyChangedCallback?

The trick is to call SetValue, that doesn't trigger the event; otherwise we'll get an infinite loop. It'll be something like this:

public string CommentsURL
{
    get { return (string)GetValue(CommentsURLProperty); }
    set { SetValue(CommentsURLProperty, value); }
}

public static readonly DependencyProperty CommentsURLProperty =
    DependencyProperty.Register("CommentsURL", typeof(string), typeof(ButtonComments),
    new PropertyMetadata(new PropertyChangedCallback(ChangedURL)));

private static void ChangedURL(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    try
    {
        string url = e.NewValue.ToString().Split(',')[0];
        new Uri(url);
        d.SetValue(e.Property, url);

        (d as ButtonComments).IsEnabled = true;
    }
    catch
    {
        (d as ButtonComments).IsEnabled = false;
    }
}
Note the refinement of the code, always avoiding the exceptions before they occur.


In the end, if someone feels curious about the result, the wepbart ended like this:



"Intellectuals solve problems; geniuses prevent them."

No comments:

Post a Comment

26.10.10

SharePoint and New Relic's RPM

I have just installed, in one of my demo servers, a copy of New Relic's RPM just to see by myself how it works.

Unbelievably it has installed without issues and it has started to work not a very common thing in the world of SharePoint.

After installing it,the free version, of course, they upgraded my licence to a gold one for 8 days to give me time to test the product in all its plenitude so a couple of minutes after deploying in my server I had a whole lot of statistics and graphs showing me once more that my web services son lentos and the response times of MOSS just after it wakes up are not the best in the world.


I have really liked the charts about the system performance. Never before was so easy for an employee to prove the server slow and that it should be improved and where (SQL, RAM or CPU they forgot about the HD)


To whom may be still dubious about trying it I can tell that (in my environment) SharePoint, the web services, the reporting services and anything else is working perfectly, or at least as perfectly as it was before the installation I've just found an error in a report thanks to RPM, the perfect excuse to bother the BI guy

Well, as I am more into complaining than into praising I'll stop talking about this product.

In other time I've had huge public servers under my boot, but now I see myself clicking fast and repeatedly to fake server traffic...

The less hair, the less power, it has always been that way.

No comments:

Post a Comment