This project has moved and is read-only. For the latest updates, please go here.

Busy Indicator Content Template Button Command

Sep 7, 2014 at 9:59 PM
I am having a small issue that I have not been able to get around implementing the Busy Indicator. As a test, I set up a small page and copied the Custom Content example code from the busy indicator onto my page. I did delete the "<ContentControl Style="{StaticResource SampleContent}"/>". I have included the code below.

For some reason, a button outside of the busy indicator is able to bind the the action I wanted completed on a button press. But the button inside the busy indicator tied to the exact same binding does nothing. Any idea what I am doing incorrectly?
<Window x:Class="CounterDisplayTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        Title="MainWindow" Height="350" Width="525"
        xmlns:local="clr-namespace:CounterDisplayTest">
    <Window.DataContext>
        <local:DeviceViewModel/>
    </Window.DataContext>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal"
                    Grid.Row="0">
            <Label>Counter Value:</Label>
            <Label Content="{Binding Count}"></Label>
        </StackPanel>
        <Button Grid.Row="1" 
                Name="Cancel" 
                Content="Cancel Content"
                Command="{Binding ClearCounter}"
                />
        <xctk:BusyIndicator IsBusy="True" DisplayAfter="0" Grid.Row="2">
            <xctk:BusyIndicator.BusyContentTemplate>
                <DataTemplate>
                    <StackPanel Margin="4">
                        <TextBlock Text="Downloading My Email" FontWeight="Bold" HorizontalAlignment="Center"/>
                        <StackPanel Margin="4">
                            <TextBlock Text="Downloading message 4/10..."/>
                            <ProgressBar Value="40" Height="15"/>
                        </StackPanel>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Button Grid.Column="0" Content="Pause" HorizontalAlignment="Right" Margin="0 0 2 0" Command="{Binding ClearCounter}"/>
                            <Button Grid.Column="1" Content="Cancel" HorizontalAlignment="Left" Margin="2 0 0 0"/>
                        </Grid>
                    </StackPanel>
                </DataTemplate>
            </xctk:BusyIndicator.BusyContentTemplate>
            <xctk:BusyIndicator.OverlayStyle>
                <Style TargetType="Rectangle">
                    <Setter Property="Fill" Value="Pink"/>
                </Style>
            </xctk:BusyIndicator.OverlayStyle>
            <xctk:BusyIndicator.ProgressBarStyle>
                <Style TargetType="ProgressBar">
                    <Setter Property="Visibility" Value="Collapsed"/>
                </Style>
            </xctk:BusyIndicator.ProgressBarStyle>
        </xctk:BusyIndicator>
    </Grid>
</Window>
Sep 8, 2014 at 1:41 PM
Well I found one solution but I am not exactly sure how it works. I am still new to WPF and am learning as I go along. I changed the button command inside the BusyIndicator to:
Command="{Binding DataContext.ClearCounter, RelativeSource={RelativeSource AncestorType={x:Type xctk:BusyIndicator}}}"
This solution came from here.
Sep 8, 2014 at 2:08 PM
Hi,

You need to set the DataContext on the button inside the BusyIndicator. Something like ;
<Button Grid.Column="0"
             Content="Pause"
             HorizontalAlignment="Right"
             Margin="0 0 2 0"
             DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
             Command="{Binding ClearCounter}"/>
Marked as answer by evclay on 9/9/2014 at 7:01 AM