Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/01/2010, 06:56
chcma
 
Fecha de Ingreso: junio-2003
Ubicación: Asturias
Mensajes: 2.429
Antigüedad: 21 años, 8 meses
Puntos: 7
DependencyProperty ¿No sirve para enlazar controles? [CERRADO]

Buenas foreros.

A ver... estoy con un ejemplo simple en Silverlight, que no sé si es que no lo estoy haciendo bien, o es que ni se puede hacer...

Tengo un TextBlock y un Button y una propiedad de tipo String. Quiero que al pulsar el botón, esta propiedad cambie de valor y el Text del TextBlock (Que está enlzadao a la propiedad) también.

Para ello tengo esto, pero no me funciona, NO HACE NADA

Xaml
Código:
                <Button Content="pulsar" Click="Button_Click" />
                
                <TextBlock Text="{Binding NombrePrueba}" />

Code-Behind
Código:
        public string NombrePrueba 
        {
            get { return (string)GetValue(NombrePruebaProperty); }
            set 
            { 
                SetValue(NombrePruebaProperty, value);

                if (PropertyChanged != null)
                    PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs("NombrePrueba"));
            }
        }

        // Using a DependencyProperty as the backing store for NombrePrueba.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty NombrePruebaProperty =
            DependencyProperty.RegisterAttached("NombrePrueba", typeof(string), typeof(Home), null);

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            
            this.NombrePrueba = "Probandoooooo";
        }

Por favor, alguien me puede decir que tengo mal ?????? Estoy desesperado de tantas pruebas que hago. Y por internet veo ejemplos, pero no veo ninguno que me aclare esta estúpida duda...
__________________
Charlie.

Última edición por chcma; 15/01/2010 a las 04:04