SL4(RC) RichTextBox and Access Violation

update: looks like this has been fixed and will work fine in  RTW

There is  a  post in silverlight forums talking about listitem in RichTextBox and editing them.

I tried this

 <RichTextBox IsReadOnly=”True” >
                <Run Text=”hello, this is a listbox”/>
                    <ItemsControl Margin=”10,0,0,0″>
                        <ListBoxItem >
                            <TextBox Text=”1. Item 1″/>
                        <ListBoxItem >
                            <TextBox Text=”2. Item 2″/>

As soon as I started editing the TextBox, got this error. looks like bug to me


Summary rows in Datagrid with multiple groups

Sometime back I posted one way to show the Summary/Totals in the group header and be able to resize individual columns when the columns are resized. That method has a limitation of not supporting nested groups. we can extend the same method to support multiple groups

Here are the steps.
we will start with what we had like in the previous sample.
1. we will add 1 GroupHeader style for each group we have. In my sample all the GroupHeader styles are same. One important change is there is a stackpanel in the GroupHeader named “ghsp” which hosts all the columns in the GroupHeader. we will add a Tag attribute and give a value of  “n-1” when  “n” is the number of groups in the datagrid. if you have 3 groups then there will be 3 group header styles and Tag attribute  will be 2, 1, 0. This is how we can differentiate the different level group headers

2. The next change is in the Resize method. ” * 20″ is for resizing the column with groupname in the group header, 20 is roughly the size of indentation for each group (could be different if you change defaults in the template)

void Resize()
            headers = datagrid1.GetChildrenByType<StackPanel>().Where(x => x.Name == “ghsp”).ToList();
            headers.ForEach(x =>
               (x.Children[0] as DataGridCell).Width = dghc.Children[1].RenderSize.Width + (Int32.Parse(x.Tag.ToString()) * 20) ;

                for (int i = 2; i < dghc.Children.Count – 2; i++)                                   
                    (x.Children[i – 1] as DataGridCell).Width = dghc.Children[i].RenderSize.Width;

3.  In the converter we have to change the way we get the totals from the CollectionViewGroup

private decimal GetProductTotal(CollectionViewGroup cvg)
            decimal total = 0;
            int counter = 0;
            while (counter < cvg.Items.Count)
                if (cvg.Items[counter] is CollectionViewGroup)
                    total += GetProductTotal(cvg.Items[counter] as CollectionViewGroup);
                    total = (cvg.Items as IEnumerable<object>).Sum(x => (x as Product).Total);

            return total;

you can download the code from here

PathListBox in SL4 – firstlook

PathListBox is new in SL4 and  is in Microsoft.Expression.Controls.dll. It makes Path based layout easy. We could make nice menu buttons with little bit more styling to remove border of the listbox, the highlight color etc

The top part of the above image is just a plain listbox with items laid out horizontally

   <ListBox x:Name=”list1″ Margin=”30″ Grid.Row=”0″>
                    <StackPanel Orientation=”Horizontal”/>

The second listbox starts with the same, but uses PathListBox in the ItemTemplate.

<ListBox x:Name=”list2″ Margin=”30″ Grid.Row=”1″ FontSize=”8″>
                    <StackPanel Orientation=”Horizontal”/>
                    <Grid  Margin=”15,0,15,0″>
                        <ec:PathListBox Margin=”0,0,0,0″ ItemsSource=”{Binding}” FontSize=”9.333″ ItemTemplate=”{StaticResource DataTemplate1}” FontWeight=”Bold” >
                                <ec:LayoutPath   SourceElement=”{Binding ElementName=path}” Distribution=”Even” Start=”.8″   Orientation=”OrientToPath” Padding=”0″ Span=”0.5″ />
                        <Ellipse Width=”40″ Height=”40″ x:Name=”path” HorizontalAlignment=”Right” Margin=”0,25,0,0″>
                          <LinearGradientBrush EndPoint=”0.5,1″ StartPoint=”0.5,0″>
                           <GradientStop Color=”Black” Offset=”1″/>
                           <GradientStop Color=”White”/>

 We start with placing a PathListbox, seting the itemssource to whatever string we are bound to and assigning it a LayoutPath which in this case is an ellipse and set few properties on the LayoutPath to customize the appearance.

Here is the codebehind to set the ItemsSource of the listbox

list2.ItemsSource = list1.ItemsSource = Enumerable.Range(0, 5).Select(x => “Option” + x.ToString());

Book Review: Next-Generation Business Intelligence Software with Silverlight

Recently, I had a chance to read the “Next-Generation Business Intelligence Software with Silverlight” book by Bart Czernicki.
The following are my thoughts on chapters which are well laid out and easy to follow

chapter 1. BI defined and concepts of BI and how it is evolving, comparision of 1.0 and 2.0
chapter 2. Why silverlight is suited for BI applications and advantages of using Silverlight
chapter 3. Structural composition of BI applications and how data crunching can be done on the client along with caching and use of isolated storage
chapter 4. Discussion on Interacting with data, caomparision of how we interact with silverlight UI vs traditional UI.
chapter 5. DataVisualization and how to apply the same using charts
chapter 6. Best practices in designing visualizations and how charts are used in visualizing, including styling charts
chapter 7. How we can enhance silverlight controls to do visual intelligence and some sample implementations
chapter 8. Collective intellignece and how existing controls can be used
chapter 9. Predictive intelligence using existing controls
chapter 10.How we can improve performance
chapter 11. Different integration options, communication between different SL apps/widgets

It is definitely a book to read if one is doing/considering a BI project using silverlight.
The code samples from chapter 3 to 11 are very good and practical.