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"
        Title="MainWindow" Height="350" Width="525"
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
        <StackPanel Orientation="Horizontal"
            <Label>Counter Value:</Label>
            <Label Content="{Binding Count}"></Label>
        <Button Grid.Row="1" 
                Content="Cancel Content"
                Command="{Binding ClearCounter}"
        <xctk:BusyIndicator IsBusy="True" DisplayAfter="0" Grid.Row="2">
                    <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"/>
                            <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"/>
                <Style TargetType="Rectangle">
                    <Setter Property="Fill" Value="Pink"/>
                <Style TargetType="ProgressBar">
                    <Setter Property="Visibility" Value="Collapsed"/>
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

You need to set the DataContext on the button inside the BusyIndicator. Something like ;
<Button Grid.Column="0"
             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