Últimamente estoy teniendo que usar bastante esta tecnología
Estaba creando un botón para añadirlo a una DataGrid como DataGridTemplateColumn y necesitaba crearme una DependencyProperty para poder hacer el Binding, hasta aquí todo más o menos claro, pero en el último momento
El truco está en llamar a SetValue, que no dispara el evento, porque si no obviamente crearíamos un bucle infinito. Algo así.
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;
}
}Al final, por si alguien siente curiosidad, el webpart ha quedado así:
"Los intelectuales arreglan los problemas, los genios los evitan."

No hay comentarios:
Publicar un comentario