Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Newbie question regarding ItemsControls RSS

2 replies

Last post Jun 21, 2009 11:40 PM by Trotter

(0)
  • Trotter

    Trotter

    Member

    1 Points

    2 Posts

    Newbie question regarding ItemsControls

    Jun 21, 2009 09:41 PM | LINK

     Hello all!

     Im still new at Silverlight so please bear with me but I am having trouble with my ItemsControl. My XAML looks like this;

        <Grid x:Name="LayoutRoot" Background="White">
    <ItemsControl Name="listBox">
    <ItemsControl.ItemTemplate>
    <DataTemplate>
    <TextBlock Text="{Binding Name}"/>
    </DataTemplate>
    </ItemsControl.ItemTemplate>
    </ItemsControl>
    </Grid>
     Here's the code;
        public partial class Page : UserControl
    {

    private Person[] _people = new Person[] {
    new Person { Name = "PersonA" }, new Person { Name = "PersonB" } };

    public Page()
    {
    InitializeComponent();
    listBox.ItemsSource = _people;
    }

    }

    public class Person
    {
    public string Name
    { get; set; }
    }

     Everything appears as it should.

    What I want to do is get the textboxes that it generates so that I can find their position on the screen. FindName always seem to return null and I cant just drill down through the content because ItemsControl doesnt inherit from content control. I'm a little stuck as to the best way to do this so any help would be greatly appreciated.

  • msalsbery

    msalsbery

    Contributor

    4432 Points

    773 Posts

    Re: Newbie question regarding ItemsControls

    Jun 21, 2009 10:03 PM | LINK

     

    You could override the PrepareContainerForItemOverride() method in an ItemsControl-derived class.

    That method will be passed an item and the container created for the item.

    See here for more details...

     

    MArk

    Mark Salsbery
  • Trotter

    Trotter

    Member

    1 Points

    2 Posts

    Re: Re: Newbie question regarding ItemsControls

    Jun 21, 2009 11:40 PM | LINK

    They make it look so easy! Thanks for the help thats me sorted for now.