Showing posts with label Silverlight. Show all posts
Showing posts with label Silverlight. Show all posts

Monday, March 1, 2010

Using ListBox instead of ScrollViewer in Silverlight

If you are thinking about scrolling image or text in silverlight, ScrollViewer might be the first thing to pop up in head. However, it is not always works.

In my scenario, there is an auction-related project. It basically use silverlight to create UI similarly as below,


The left Viewer is the connection and biding information. The right one is the DataGrid displaying the latest price for each items.


In .xaml file, I was using ScrollViewer,
 <ScrollViewer Margin="25,0,-7,8" x:Name="connectViewer">
                <TextBlock x:Name="lblMessages" Margin="1" TextWrapping="Wrap" Height="860" FontSize="8"></TextBlock>
            </ScrollViewer>

           
In code behind,
lblMessages.Text += message + Environment.NewLine;

The problem is there is a limitation in the length of TextBlock. Because there are so many biding information which reach the limit of TextBlock, the new coming biding info won't be displayed in ScrollViewer.


Solution:
Use ListBox DataTemplate intead.

Code in .xaml
 <ListBox x:Name="listBoxConnectInfo" Margin="25,0,-7,8">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding}" TextAlignment="Left" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
 </ListBox>

In code behind,
listBoxConnectInfo.Items.Add(message);

So for every each time, it adds a TextBlock into ListBox and bind the message to the Text property.The more important thing is, it is scrollable as well.


Hope that helps -:).
Please don't hesitate to leave comments if you have better idea.

Friday, February 26, 2010

Resharper 4.5 issue with SilverLight RIA Service in VS 2008

Recently, I dive in a little bit the RIA Service in SilverLight 3 following Tim Heuer's great video which available here
http://silverlight.net/learn/videos/all/net-ria-services-intro/.



I followed the video to create the ADO.NET Entity Data Model and Domain Service Class. Everything works just fine until


The AdvDomainContext cannot be found. The reason is RIA service use Generated_Code to share code between Server and silverlight which technically exclude from project.


So any code references Generated_Code in silverlight can not be resolved by Resharper.


Solution:
1. Show all file in VS 2008





















2. Include Generated_Code into project






















Then, Resharper can pick up the class now.
By the way, it might pop up warning when you dubug the project


Just go will the "continue".

It works now :-)