Silverlight ListBox control
Last post 05-13-2008 9:19 PM by rankief. 7 replies.
Sort Posts:
05-12-2008 8:27 PM
Silverlight ListBox control

Hi, im using listbox control in my page with template specifying a single textblock.

how am i able to set the style at runtime for ListBoxText ??? as the style is different for different record.

<ListBox x:Name="ListBoxObj" Width="120" HorizontalAlignment="Stretch" Canvas.Top="18" MaxHeight="100" Visibility="Collapsed"

SelectionChanged="ListBoxObj_SelectionChanged" >

<ListBox.ItemTemplate >

<DataTemplate >

<TextBlock x:Name="ListBoxText" Text="test"></TextBlock>

</DataTemplate>

</ListBox.ItemTemplate>

</ListBox>


 

rankief

Loading...
Joined on 08-10-2006
Posts 6
05-12-2008 10:09 PM
Marked as Answer
Re: Silverlight ListBox control

 I think you can do it in Textblock.Loaded event

 <TextBlock x:Name="ListBoxText" Text="test" Loaded="TextBlock_Loaded"></TextBlock>

private void TextBlock_Loaded(object sender, RoutedEventArgs e)

{

   TextBlock t = sender as TextBlock;

    DataObject data = t.DataContext as DataObject;

    // based on your data you can set the style

}

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 1,534
05-13-2008 6:17 AM
Re: Silverlight ListBox control

hi dude

t.DataContext

 which means i need to use reflection to get the value.

Yes right i will not know the object type binded to the dropdownlist

rankief

Loading...
Joined on 08-10-2006
Posts 6
05-13-2008 11:15 AM
Re: Silverlight ListBox control

If you want to change the style based on the Text on the TextBlock you can just check t.Text.

If you want to change the style based on some other data on that row, either you have your pre-defined DataObject, or if you do not know the type before hand you have to use reflection to get the value or a particular field (I have never tried this way, but somebody else did it).

 

 

 

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 1,534
05-13-2008 8:27 PM
Re: Silverlight ListBox control

hi dude,

i tried using reflection

based +- 200 records in the list box.

it takes quite a while to load the list items.

and my machine is dual core 1 gb

 

any comments/idea?

rankief

Loading...
Joined on 08-10-2006
Posts 6
05-13-2008 9:03 PM
Re: Silverlight ListBox control

I remember seeing a post by someone reported bad performance with ListBox binding to a large set of data in this forum. I don't know if I can find the post. But anyway, if you find it is slow, then it might be the case in the beta release version. 

 

 

 

 

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 1,534
05-13-2008 9:07 PM
Re: Silverlight ListBox control

OK, I found the old post talking about this problem and answer from Microsoft people:

 http://silverlight.net/forums/p/15333/50621.aspx#50621

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

sladapter

Loading...
Joined on 03-05-2008
Indiana, US
Posts 1,534
05-13-2008 9:19 PM
Re: Silverlight ListBox control

Thanks ALOT!

will change to datagrid if possible.

rankief

Loading...
Joined on 08-10-2006
Posts 6