locked
Using datatemplate object in code behind RRS feed

  • Question

  • Hi, I'm working on a silverlight5 project. I have a DataTemplate like ; <UserControl.Resources> <ResourceDictionary> <DataTemplate x:Key="EmailConfigPage"> <Grid Width="700" Height="400"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Grid Grid.Column="1"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <TextBlock TextWrapping="Wrap" Width="400" HorizontalAlignment="Left" Margin="16,16,16,10" FontSize="20" FontWeight="600" Text="Email Configuration" /> <Grid HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <TextBlock Text="E-mail Address:" Margin="0,0,10,0" Grid.Row="3" VerticalAlignment="Center" /> <TextBox x:Name="tbEmailAddress" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Width="200" HorizontalAlignment="Left" /> </Grid> </Grid> </Grid> </DataTemplate> </ResourceDictionary> </UserControl.Resources> I can get datatemplate content and then I need to use "tbEmailAddress" object in code behind. Because of it is in a datatemplate, i can not use directly by its name. How can i do this ? Can you help me ? Thank you
    Tuesday, July 24, 2012 3:24 AM

Answers

  • Thank you for your answer i can reach my objects:)
    Tuesday, July 24, 2012 4:55 AM

All replies

  • Because of it is in a datatemplate, i can not use directly by its name. How can i do this ? Can you help me ? Thank you

    var grid = (this.Resources["EmailConfigPage"] as DataTemplate).LoadContent() as Grid;
    
    var tbEmailAddress = grid.FindName("tbEmailAddress") as TextBox;
    
    tbEmailAddress.Text= "Add your Text here ";

    let me know if you need anything else.

    • Proposed as answer by Verma.Manish Monday, November 9, 2015 2:01 PM
    Tuesday, July 24, 2012 3:42 AM
  • Thank you for your answer i can reach my objects:)
    Tuesday, July 24, 2012 4:55 AM
  • Thank you for your answer i can reach my objects:)

    You should mark my reply as answered not yours..............

    Tuesday, July 24, 2012 7:23 AM