Lately I'm using a lot this technology
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
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; } }
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