Unable to set Visibility control for SpocketControl

Feb 28, 2012 at 9:07 AM

In my xaml code the Visibility property is set to Collapsed. In my code on button clicked event I set its Visibility property to Visible but it doesn't show.

Here's the code:

        private void finishConfigButton_Click(object sender, RoutedEventArgs e)
        {
            newUser.Name = newNameTextBox.Text;
            emailCheckBusyIndicator.Visibility = System.Windows.Visibility.Visible;

            if (newNameTextBox.Text == "" && newEmailTextBox.Text == "" && newUsernameTextBox.Text == "" && newPasswordPasswordBox.Password == "")
            {
                errorLabel.Visibility = System.Windows.Visibility.Visible;
                emailCheckBusyIndicator.Visibility = System.Windows.Visibility.Collapsed;
            }

            if (!newUser.validateNewUserInformation(newNameTextBox.Text, newEmailTextBox.Text, newUsernameTextBox.Text, newPasswordPasswordBox.Password, saveInfoCheckBox.IsChecked))
            {
                errorLabel.Visibility = System.Windows.Visibility.Visible;
                emailCheckBusyIndicator.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                errorLabel.Visibility = System.Windows.Visibility.Collapsed;

                string systemDriveLetter = Environment.SystemDirectory.Substring(0, 1);
                string activeSystemUsername = Environment.UserName;

                if (saveInfoCheckBox.IsChecked == true)
                    newUser.SaveAuthInfo = true;
                else
                    newUser.SaveAuthInfo = false;
                string activeDir = systemDriveLetter + @":\Users\" + activeSystemUsername + @"\My Documents\SSK\Users";
                string newPath = System.IO.Path.Combine(activeDir, newNameTextBox.Text);
                Directory.CreateDirectory(newPath);
                newUser.SaveUserData(newUser, saveInfoCheckBox.IsChecked);

                newUserSettings.SetDefaultValues();
                activeDir = systemDriveLetter + @":\Users\" + activeSystemUsername + @"\My Documents\SSK\Users\" + newUser.Name;
                newPath = System.IO.Path.Combine(activeDir, "Settings");
                Directory.CreateDirectory(newPath);
                newUserSettings.SaveSettings(newUser, newUserSettings);

                IntelliMonitorWindow intelliMonitor = new IntelliMonitorWindow();
                intelliMonitor.CurrentUser = newUser;
                intelliMonitor.CurrentUserSettings = newUserSettings;
                intelliMonitor.Show();
                this.Close();
            }

        }
Coordinator
Feb 28, 2012 at 11:37 AM

Hi,

 Could you also share the XAML code where you have declared the emailCheckBusyIndicator? What all properties of the SprocketControl have you set?

Regards,

Ratish Philip

Feb 28, 2012 at 12:06 PM

Sorry, here's my XAML:

<bi:SprocketControl Grid.Column="0"
                                  HorizontalAlignment="Right"
                                  x:Name="emailCheckBusyIndicator"
                                  Margin="0,0,5,85"
                                  VerticalAlignment="Bottom"
                                  TickColor="LawnGreen"
                                  Width="30"
                                  Height="30"
                                  TickWidth="3"
                                  TickCount="12"
                                  StartAngle="-90"
                                  IsIndeterminate="False"
                                  Interval="60" 
                                  LowestAlpha="50"
                                  AlphaTicksPercentage="50" Visibility="Collapsed" />

Coordinator
Feb 28, 2012 at 3:36 PM

Since you are using the SprocketControl as a BusyIndicator, you have to set the IsIndeterminate property to True. Then only it will show the spinning SprocketControl.

If you set  the IsIndeterminate property as False, it behaves like a normal ProgressBar and you have to set the Progress value explicitly. Based on the value set, the appropriate number of spokes of the SprocketControl will be visible and the control will not be spinning.

Regards,

Ratish Philip

Feb 28, 2012 at 4:32 PM

Yes that definitely was an error. But even with IsIdeterminate property set to True the control doesn't show up. When I set up a Visibility property inside designer it works, but it doesn't works inside code so I suspect that there is an error. As you can see when I click the button the control should appear, then I do some checks and sends an email. Finally, I navigate to the second window and close this one. It takes some time to send an email so it must be visible until that task is completed.

Coordinator
Feb 29, 2012 at 2:32 AM

Hi,

    I checked your code snippet here. It is working fine here. Here is the XAML

 

<Window x:Class="TestSprocket.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wpfspark="clr-namespace:WPFSpark;assembly=WPFSpark"
        Title="MainWindow"
        Height="350"
        Width="525">
    <Grid>
        <wpfspark:SprocketControl x:Name="sprocketCtrl"
                                  HorizontalAlignment="Right"
                                  Margin="0,0,5,85"
                                  VerticalAlignment="Bottom"
                                  TickColor="LawnGreen"
                                  Width="30"
                                  Height="30"
                                  TickWidth="3"
                                  TickCount="12"
                                  StartAngle="-90"
                                  IsIndeterminate="True"
                                  Interval="60"
                                  LowestAlpha="50"
                                  AlphaTicksPercentage="50"
                                  Visibility="Collapsed"></wpfspark:SprocketControl>
        <Button Width="100"
                Height="30"
                HorizontalAlignment="Center"
                VerticalAlignment="Bottom"
                Margin="20"
                Content="Make Visible"
                Click="Button_Click"></Button>
    </Grid>
</Window>

 

Here is the code behind

 

using System.Windows;

namespace TestSprocket
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            sprocketCtrl.Visibility = Visibility.Visible;
        }
    }
}

 

In your code for the click handler, after setting the visibility of the emailCheckBusyIndicator  to Visible there are two places where you are setting 

emailCheckBusyIndicator.Visibility = System.Windows.Visibility.Collapsed;

Just ensure that this line is not being executed else you will not be able to see the emailCheckBusyIndicator.

Feb 29, 2012 at 9:21 AM

I figure it out. It was a bug in code. Thank you for persistence and fast answers. I couldn't figure it out without your help.

Coordinator
Feb 29, 2012 at 9:25 AM

Glad to know you found out the bug!