开发者

Silverlight not initializing controls

开发者 https://www.devze.com 2023-04-07 19:51 出处:网络
I\'m trying to add some values in several controls in my silverlight page (textboxes, datepickers...) but it seems like some of them are never initialize (until user sets any value manually).

I'm trying to add some values in several controls in my silverlight page (textboxes, datepickers...) but it seems like some of them are never initialize (until user sets any value manually).

I've tried it by been suscribed to the "Loaded" event in the page's code behind but it doesn't work... (I thought it was because of the order it was being initialized).

I've read that this is one of 开发者_开发问答silverlight limitations but maybe there is any workaround...

Any idea?? Thanks in advance.

Some code to illustrate it, first the xaml controls:

<sdk:Label Target="{Binding ElementName=txtNumeroColegiado}" Content="Nº Colegiado" HorizontalAlignment="Right" Margin="5,0" Name="label2" VerticalAlignment="Center" />
<TextBox Margin="5,0" Name="txtNumeroColegiado" TabIndex="27" Text="{Binding Medico.colegiado, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" VerticalAlignment="Center" Grid.Column="1" />

<sdk:Label Target="{Binding ElementName=txtNombreComercial}" Content="Nombre Comercial" HorizontalAlignment="Left" Margin="5,0" Name="label4" VerticalAlignment="Center" Grid.Column="2" />
<TextBox Margin="5,0" Name="txtNombreComercial" TabIndex="27" Text="{Binding Medico.nombrecomercial, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" VerticalAlignment="Center" Grid.Column="3" />

And this is my conde behind:

public DatosMedico()
{
    InitializeComponent();
    this.Loaded += new RoutedEventHandler(DatosMedico_Loaded);
}

void DatosMedico_Loaded(object sender, RoutedEventArgs e)
{
     this.txtNombreComercial.GetBindingExpression(TextBox.TextProperty).UpdateSource();
     this.txtNumeroColegiado.GetBindingExpression(TextBox.TextProperty).UpdateSource();
}

When it tries to run "updateSource", these textboxes are null (but they are working perfectly in the page...). Apparently they are initialized when user inputs some text...


At guess, the DataContext is either not being set or not set to the object you are expecting it to be set to. Check the output window in VS when debugging, do you see any complaints about binding?


It was solutioned by deleting a "ContentPresenter" that had many controls inside.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号