locked
How to access the UI Element present inside the data template in metro apps? RRS feed

  • Question

  • Hi all,

    <DataTemplate x:Key="StandardMyTemplate">
    
            <Grid Height="110" Margin="6">
    
                <Grid.ColumnDefinitions>
    
                    <ColumnDefinition Width="Auto"/>
    
                    <ColumnDefinition Width="*"/>
    
                </Grid.ColumnDefinitions>
    
                <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}" Width="110" Height="110">
    
                    <Image Source="{Binding Image}" Stretch="UniformToFill"/>
    
                </Border>
    
                <StackPanel Grid.Column="1" VerticalAlignment="Top" Margin="10,0,0,0">
    
                    <TextBlock x:Name = "Title" Text="{Binding Title}" Style="{StaticResource TitleTextStyle}" TextWrapping="NoWrap"/>
    
                    <TextBlock  x:Name = "Subtitle" Text="{Binding Subtitle}" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap"/>
    
                    <TextBlock x:Name = "Description"Text="{Binding Description}" Style="{StaticResource BodyTextStyle}" MaxHeight="60"/>
    
                </StackPanel>
    
            </Grid>
    
        </DataTemplate>
    

    Just i need to update the Title (Textbox) value from c# ( ie itemDetailpage.xaml ).
    Atcually i tried below two way code :

    var itemName = Application.current.resource["Title"] as Textbox;
    string text = "hello";
    itemName.text = text;

    second way :

    http://nishantcop.blogspot.in/2011/08/access-templated-child-in-silverlight.html

    in this above site ,author followed three approaches..but it is not working properly for me ...i think i`m missing something .please help me out how to access the UI element that present inside the data template ?

    Thanks in Advance


    Lavanya S

    Tuesday, April 30, 2013 4:15 AM

Answers

  • go through this links

    http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/fb16c929-7318-41de-9ef4-fb62cb1bb45f

    http://msdn.microsoft.com/en-IN/library/bb613579.aspx

    you may get some solution.

    Please remember to mark the replies as answers it will help others too.


    • Edited by RishiRajIT Tuesday, April 30, 2013 6:17 AM
    • Proposed as answer by RishiRajIT Tuesday, April 30, 2013 6:17 AM
    • Marked as answer by SparkleLavs Thursday, May 2, 2013 1:04 PM
    Tuesday, April 30, 2013 5:49 AM