views:

214

answers:

0

Hello,

I'm working on a Silverlight interface that among other things needs to display a bunch of URLs and the HTML elements they contain in a TreeView control. The user may view the tree in two modes: read only (contains only the URLs and HTML elements selected by the user) and edit (contains everything). In order to do this I use two controls, each data bound to a different ObservableCollection. When switching modes, I just make one visible and the other one collapsed. Functionally this works fine, however the tree is quite large and it freezes the interface for a while when switching to the edit mode tree.

This may not be the best way to do this task but I haven't found another so if anyone knows of a more efficient way I'm more than open to suggestions.

Back to the main issue, I'd like to show a busy indicator when transitioning from one view mode to another. Setting BusyIndicator.IsBusy to true when the switch button's onclick function is called and then reverting to false when it leaves doesn't work. No indicator is shown. I don't know where else I should place it.

I also did a small experiment. I placed a temporary button that flips the value of BusyIndicator.IsBusy whenever clicked. In edit mode, when I click the aforementioned button the UI freezes for a few seconds then shows the busy indicator on top a "disabled" tree. The same thing happens when I click the button again to remove the indicator. Maybe this is related to the indicator not showing, I'm not sure.

Sorry for the long text, but does anyone have any suggestion on how to fix this one way or another?

The code bellow is inside the BusyIndicator. I haven't included the BusyIndicator because it's not displayed properly in the preview.

<Grid HorizontalAlignment="Stretch">
    <!--PageElementsTreeView template-->
    <Grid.Resources>
        <controls2:HierarchicalDataTemplate x:Key="PageElementTemplate">
            <StackPanel Orientation="Horizontal">
                <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}"/>
                <TextBlock Text="{Binding Name}"/>
            </StackPanel>
        </controls2:HierarchicalDataTemplate>

        <controls2:HierarchicalDataTemplate x:Key="URLTemplate" 
                                        ItemTemplate="{StaticResource PageElementTemplate}"
                                        ItemsSource="{Binding Elements}">
            <StackPanel Orientation="Horizontal">
                <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}" IsThreeState="True"/>
                <TextBlock Text="{Binding Url}"/>
            </StackPanel>
        </controls2:HierarchicalDataTemplate>

        <controls2:HierarchicalDataTemplate x:Key="PageElementTemplateReadOnly">
            <StackPanel Orientation="Horizontal">
                <CheckBox IsChecked="{Binding IsSelected}" IsEnabled="False"/>
                <TextBlock Text="{Binding Name}"/>
            </StackPanel>
        </controls2:HierarchicalDataTemplate>

        <controls2:HierarchicalDataTemplate x:Key="URLTemplateReadOnly" 
                                        ItemTemplate="{StaticResource PageElementTemplateReadOnly}"
                                        ItemsSource="{Binding Elements}">
            <StackPanel Orientation="Horizontal">
                <CheckBox IsChecked="{Binding IsSelected}" IsThreeState="True" IsEnabled="False"/>
                <TextBlock Text="{Binding Url}"/>
            </StackPanel>
        </controls2:HierarchicalDataTemplate>
    </Grid.Resources>
    <!--PageElements scrollable TreeView -->
    <ScrollViewer VerticalScrollBarVisibility="Auto" x:Name="PageElementsSV" Visibility="Collapsed" >
        <controls:TreeView x:Name="PageElementsTree" ItemTemplate="{StaticResource URLTemplate}"
                       ItemsSource="{Binding}">
        </controls:TreeView>
    </ScrollViewer>

    <ScrollViewer VerticalScrollBarVisibility="Auto" x:Name="PageElementsReadOnlySV" Visibility="Collapsed">
        <controls:TreeView x:Name="PageElementsTreeReadOnly" ItemTemplate="{StaticResource URLTemplateReadOnly}"
                       ItemsSource="{Binding}">
        </controls:TreeView>
    </ScrollViewer>
</Grid>