I am using the BusyIndicator from the WPF Toolkit in my WPF application. I am trying to access the label (artistLabel) from the C# code behind. Unfortunately I cannot access the label if it is inside the busy indicator. I am sure that it's some kind of binding or scope issue. Any help would be appreciated. Thanks!

<wpfx:BusyIndicator Name="BusyBar" IsBusy="True">
            <wpfx:BusyIndicator.BusyContentTemplate>
                <DataTemplate>
                    <StackPanel Margin="4">
                        <TextBlock Text="Adding music to library" FontWeight="Bold" HorizontalAlignment="Center" Padding="0,0,0,10"/>

                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Label Content="Artist: " Grid.Column="0" Grid.Row="0"></Label>
            This line---->  <Label Grid.Column="1" Grid.Row="0" Name="artistLabel" ></Label>
                        </Grid>
                        <StackPanel Margin="4">
                            <ProgressBar Value="80" Height="15"/>
                        </StackPanel>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Button Grid.Column="0" Grid.Row="1" Content="Cancel" HorizontalAlignment="Right" Margin="2 0 0 0"/>
                        </Grid>
                    </StackPanel>
                </DataTemplate>
            </wpfx:BusyIndicator.BusyContentTemplate>
            <wpfx:BusyIndicator.OverlayStyle>
                <Style TargetType="Rectangle">
                    <Setter Property="Fill" Value="#ffffeeee"/>
                </Style>
            </wpfx:BusyIndicator.OverlayStyle>
            <wpfx:BusyIndicator.ProgressBarStyle>
                <Style TargetType="ProgressBar">
                    <Setter Property="Visibility" Value="Collapsed"/>
                </Style>
            </wpfx:BusyIndicator.ProgressBarStyle>
            <!--<ContentControl Style="{StaticResource SampleContent}"/>-->
        </wpfx:BusyIndicator>

Hi Try this.. But i am not sure about this..
BusyBar.Template.FindName("artistLabel");

Actually that worked inside of the xaml.cs file. How can it get it to work inside of a class of a different scope?

create an object for that xaml.cs class and access it

Are you talking about instantiating that class? I don't think that will work, I have just noticed that the BusyBar Object falls out of scope once outside of the MenuItem_Click_AddFolder function.

I just moved everything into one class and got rid of the busy indicator.

I also ran into this problem and haven't find the solution to fix it.Could anyone help us and give us a clear answer?

Hi,everyone.I found a solution that could fix this issue,which was to use BusyIndicator.BusyContent instead of BusyIndicator.BusyContentTemplate and move everything from the DataTemplate of BusyIndicator.BusyContentTemplate to BusyIndicator.BusyContent.And you can access xaml elements from C# codes behind.The sample codes are shown as below.I hope it would help you.Please forgive and correct me if I made mistakes.

XMAL Codes:
<Window x:Class="TestBusyInCon.Window1"
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" MinWidth="800" MinHeight="520" Width="800" Height="520" WindowStartupLocation="CenterScreen">
    <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
        <xctk:BusyIndicator x:Name="busyIn" DisplayAfter="0">
            <xctk:BusyIndicator.BusyContent>
                <StackPanel Height="200" Width="300">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="28"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="50"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="Smile" FontWeight="Bold" Foreground="DarkBlue" Grid.Row="0" Grid.Column="0"></TextBlock>
                        <Button Content="Close" Height="25" Width="50" HorizontalAlignment="Right" VerticalAlignment="Top" Grid.Row="0" Grid.Column="1" Cursor="Hand" Click="HideBusyIn"></Button>
                    </Grid>


                    <TextBlock x:Name="tblHappywords"  FontWeight="Bold" HorizontalAlignment="Center" Foreground="DarkBlue"></TextBlock>
                    <Separator Background="White" Margin="0,5,0,5"></Separator>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Height="60" >
                        <Button Content="Change Mood"  Margin="0,0,20,0" Width="100" Height="25" Click="ChangeMood" Cursor="Hand"></Button>
                    </StackPanel>
                    <xctk:WatermarkTextBox x:Name="txtHappywords" Watermark="Enter happy words here."  
                              BorderBrush="#ccc" BorderThickness="2" Width="205" Height="25" Margin="4"></xctk:WatermarkTextBox>
                </StackPanel>
            </xctk:BusyIndicator.BusyContent>
            <xctk:BusyIndicator.ProgressBarStyle>
                <Style TargetType="ProgressBar">
                    <Setter Property="Visibility" Value="Collapsed"></Setter>
                </Style>
            </xctk:BusyIndicator.ProgressBarStyle>
            <ContentControl>
                <StackPanel Height="70" >
                    <TextBlock Text="Click the button below to show the busy indicator."></TextBlock>
                    <Button x:Name="btnTest" Content="Test" Margin="0,20,20,0" Width="80" Height="25" Click="TestBusyIn" Cursor="Hand"></Button>
                </StackPanel>
            </ContentControl>
        </xctk:BusyIndicator>
    </StackPanel>
</Window>





C# Codes:
using System.Windows;

namespace TestBusyInCon
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void TestBusyIn(object sender, RoutedEventArgs e)
        {
            this.tblHappywords.Text = "Are you happy today?";
            this.txtHappywords.Text=string.Empty;
            this.busyIn.IsBusy = true;
        }

        private void HideBusyIn(object sender, RoutedEventArgs e)
        {
            this.busyIn.IsBusy = false;
        }

        private void ChangeMood(object sender, RoutedEventArgs e)
        {
            string happywords = this.txtHappywords.Text.Trim();
            if (!string.IsNullOrEmpty(happywords))
            {
                this.tblHappywords.Text = this.txtHappywords.Text;
            }
        }
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.