Results 1 to 8 of 8

Thread: Cannot seem to change Progress Bar properties or visibility in WPF / VB.Net

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2019
    Posts
    5

    Question Cannot seem to change Progress Bar properties or visibility in WPF / VB.Net

    I am trying to get a progress bar to begin its automation in the click event of a button control and stop the automation on completion of the click event. Prior to that, I set the IsIndeterminate property to true and just hid the progress bar until the user clicks on my search button, which then, i would set the visibility to visible (or, value 0). None of these are working. Then, I tried to use both BeginInvoke and Invoke from the Dispatcher object. Still no luck. Then, I implemented INotifyPropertyChanged on my WPF window. Again, I would raise the event when the IsIndeterminate property was changed either from off to on or on to off on completion. Again, nothing is happening. Most of the examples for the progress bar online is using c# code. Most of the time, I am able to convert it but again, none of what I am attempted is working. I'm starting to think perhaps my install of Visual Studio could be missing something. Any help on this would be greatly appreciated. Thanks, South Side Rob

  2. #2

    Thread Starter
    New Member
    Join Date
    Jul 2019
    Posts
    5

    Re: Cannot seem to change Progress Bar properties or visibility in WPF / VB.Net

    Here is just a taste of my code behind. When I step through the code, it actually changes the property of the progressbar (named pb) to IsIndeterminate, however, the UI never shows the animation. I even can comment out the 2nd Invoke statement in my btnSearch_Click event. When I do that, the animation begins after the event is completed (I love WPF except for UI control)

    Code:
        Private Sub btnSearch_Click(sender As Object, e As RoutedEventArgs) Handles btnSearch.Click
    
            pb.Dispatcher.Invoke(AddressOf ChangeProgBar)
    
            If ValidateMainWindow(Me) = True Then
                ProcessDefaultQuery(Me)
            End If
    
            pb.Dispatcher.Invoke(AddressOf ChangeProgBar)
    
        End Sub
    
        Private Sub ChangeProgBar()
    
            If pb.IsIndeterminate = False Then
                pb.IsIndeterminate = True
            Else
                pb.IsIndeterminate = False
            End If
    
        End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2019
    Posts
    5

    Re: Cannot seem to change Progress Bar properties or visibility in WPF / VB.Net

    Here is just a taste of my code behind. When I step through the code, it actually changes the property of the progressbar (named pb) to IsIndeterminate, however, the UI never shows the animation. I even can comment out the 2nd Invoke statement in my btnSearch_Click event. When I do that, the animation begins after the event is completed (I love WPF except for UI control)

    Code:
        Private Sub btnSearch_Click(sender As Object, e As RoutedEventArgs) Handles btnSearch.Click
    
            pb.Dispatcher.Invoke(AddressOf ChangeProgBar)
    
            If ValidateMainWindow(Me) = True Then
                ProcessDefaultQuery(Me)
            End If
    
            pb.Dispatcher.Invoke(AddressOf ChangeProgBar)
    
        End Sub
    
        Private Sub ChangeProgBar()
    
            If pb.IsIndeterminate = False Then
                pb.IsIndeterminate = True
            Else
                pb.IsIndeterminate = False
            End If
    
        End Sub

  4. #4
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Cannot seem to change Progress Bar properties or visibility in WPF / VB.Net

    Hi,

    Can you please post the XAML that contains the DataGrid control and the IsIndeterminate property?

    - kgc
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2019
    Posts
    5

    Re: Cannot seem to change Progress Bar properties or visibility in WPF / VB.Net

    Here you go. Thanks for looking at this. I really appreciate it. Since my post yesterday, I began to replace it with a label control that I am trying to use with a dispatchtimer object and I'm getting the same results. It only wants to run after the processing is completed. Maybe I need this broken up in different threads from the start..

    Code:
    <Window x:Class="MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:MaintGearSQL"
            mc:Ignorable="d"
            FontFamily="Candara" FontSize="14" Height="900" Title="MaintGearSQL" Width="1220">
    
        <!--This sets defaults for controls-->
        <Window.Resources>
    
            <Style TargetType="Button">
                <Setter Property="Margin"     Value="5" />
                <Setter Property="Height"     Value="22" />
                <Setter Property="Width"      Value="90" />
                <Setter Property="FontFamily" Value="Candara" />
                <Setter Property="FontSize"   Value="14" />
            </Style>
    
            <Style TargetType="ComboBox">
                <Setter Property="FontFamily" Value="Candara" />
                <Setter Property="FontSize"   Value="14" />
                <Setter Property="Height"     Value="22" />
                <Setter Property="Margin"     Value="5" />
                <Setter Property="MaxWidth"   Value="400" />
                <Setter Property="MinWidth"   Value="400" />
            </Style>
    
            <Style TargetType="DataGrid">
                <Setter Property="Margin"     Value="5" />
                <Setter Property="FontFamily" Value="Candara" />
                <Setter Property="FontSize"   Value="14" />
                <Setter Property="MinHeight"  Value="300" />
                <Setter Property="MaxHeight"  Value="300" />
            </Style>
            
            <Style TargetType="Label">
                <Setter Property="Margin"              Value="5" />
                <Setter Property="HorizontalAlignment" Value="Right" />
                <Setter Property="FontFamily"          Value="Candara" />
                <Setter Property="FontSize"            Value="14" />
            </Style>
    
            <Style TargetType="TabItem">
                <Setter Property="FontFamily" Value="Candara" />
                <Setter Property="FontSize"   Value="14" />
            </Style>
    
            <Style TargetType="TextBlock">
                <Setter Property="Margin"     Value="5" />
                <Setter Property="FontFamily" Value="Candara" />
                <Setter Property="FontSize"   Value="14" />
            </Style>
    
            <Style TargetType="TextBox">
                <Setter Property="Margin"     Value="5" />
                <Setter Property="Height"     Value="22" />
                <Setter Property="Width"      Value="150" />
                <Setter Property="FontFamily" Value="Candara" />
                <Setter Property="FontSize"   Value="14" />
            </Style>
    
        </Window.Resources>
    
        <Grid Name="grdMain">
    
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
    
            <!-- Row 0 -->
            <Menu Grid.Row="0">
                <MenuItem Header="_File" />
                <MenuItem Header="_Edit" />
                <MenuItem Header="_View" />
            </Menu>
    
            <!-- Row 1 -->
            <TabControl Name="tcMain" Grid.Row="1">
                <TabItem Name="tabDefaultQuery" Header="Default Query">
                    <Grid Name="grdDefaultQuery">
    
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />     <!-- Row 0 -->
                            <RowDefinition Height="Auto" />     <!-- Row 1 -->
                            <RowDefinition Height="Auto" />     <!-- Row 2 -->
                            <RowDefinition Height="Auto" />     <!-- Row 3 -->
                            <RowDefinition Height="Auto" />     <!-- Row 4 -->
                            <RowDefinition Height="Auto" />     <!-- Row 5 -->
                            <RowDefinition Height="Auto" />     <!-- Row 6 -->
                            <RowDefinition Height="Auto" />     <!-- Row 7 -->
                            <RowDefinition Height="Auto" />     <!-- Row 8 -->
                            <RowDefinition Height="Auto" />     <!-- Row 9 -->
                            <RowDefinition Height="Auto" />     <!-- Row 10 -->
                            <!--<RowDefinition Height="*" />         Row 11 -->
                            <RowDefinition Height="Auto" />     <!-- Row 12 -->
                        </Grid.RowDefinitions>
    
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />   <!-- Col 0 -->
                            <ColumnDefinition Width="Auto" />   <!-- Col 1 -->
                            <ColumnDefinition Width="Auto" />   <!-- Col 2 -->
                            <ColumnDefinition Width="Auto" />   <!-- Col 3 -->
                            <ColumnDefinition Width="Auto" />   <!-- Col 4 -->
                            <ColumnDefinition Width="Auto" />   <!-- Col 5 -->
                            <ColumnDefinition Width="Auto" />   <!-- Col 6 -->
                            <ColumnDefinition Width="*" />      <!-- Col 7 -->
                            <ColumnDefinition Width="5" />      <!-- Col 8 -->
                        </Grid.ColumnDefinitions>
    
                        <!-- Row 0 -->
                        <Label Content="Tooth Form"   Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" />
                        <ComboBox Name="cboToothForm" Grid.Row="0" Grid.Column="2" Grid.ColumnSpan="4" ItemsSource="{Binding}" />
    
                        <!-- Row 1 -->
                        <Label Content="Teeth"        Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" />
                        <Label Content="From"         Grid.Row="1" Grid.Column="2" />
                        <TextBox Name="txtTeethFrom"  Grid.Row="1" Grid.Column="3" />
                        <Label Content="To"           Grid.Row="1" Grid.Column="4" />
                        <TextBox Name="txtTeethTo"    Grid.Row="1" Grid.Column="5" />
    
                        <!-- Row 2 -->
                        <Label Content="Pitch (Basic)"    Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" />
                        <Label Content="From"             Grid.Row="2" Grid.Column="2" />
                        <TextBox Name="txtBasicPitchFrom" Grid.Row="2" Grid.Column="3" />
                        <Label Content="To"               Grid.Row="2" Grid.Column="4" />
                        <TextBox Name="txtBasicPitchTo"   Grid.Row="2" Grid.Column="5" />
    
                        <!-- Row 3 -->
                        <Label Content="Outside Diameter"      Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" />
                        <Label Content="From"                  Grid.Row="3" Grid.Column="2" />
                        <TextBox Name="txtOutsideDiameterFrom" Grid.Row="3" Grid.Column="3" />
                        <Label Content="To"                    Grid.Row="3" Grid.Column="4" />
                        <TextBox Name="txtOutsideDiameterTo"   Grid.Row="3" Grid.Column="5" />
    
                        <!-- Row 4 -->
                        <Label Content="Face Width"      Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" />
                        <Label Content="From"            Grid.Row="4" Grid.Column="2" />
                        <TextBox Name="txtFaceWidthFrom" Grid.Row="4" Grid.Column="3" />
                        <Label Content="To"              Grid.Row="4" Grid.Column="4" />
                        <TextBox Name="txtFaceWidthTo"   Grid.Row="4" Grid.Column="5" />
    
                        <!-- Row 5 -->
                        <Label Content="Finish Code"     Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" />
                        <ComboBox Name="cboFinishCode"   Grid.Row="5" Grid.Column="2" Grid.ColumnSpan="4" ItemsSource="{Binding}" />
    
                        <!-- Row 6 -->
                        <Label Content="Product Line"    Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2" />
                        <ComboBox Name="cboProductLine"  Grid.Row="6" Grid.Column="2" Grid.ColumnSpan="4" ItemsSource="{Binding}" />
    
                        <!-- Row 7 -->
                        <Label Content="Part Type"       Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="2" />
                        <ComboBox Name="cboPartType"     Grid.Row="7" Grid.Column="2" Grid.ColumnSpan="4" ItemsSource="{Binding}" />
    
                        <!-- Row 8 -->
                        <Label Content="Material"        Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="2" />
                        <ComboBox Name="cboMaterial"     Grid.Row="8" Grid.Column="2" Grid.ColumnSpan="4" ItemsSource="{Binding}" />
    
                        <!-- Row 9 -->
                        <Label Content="Special Codes"   Grid.Row="9" Grid.Column="0" Grid.ColumnSpan="2" />
                        <ComboBox Name="cboSpecialCodes" Grid.Row="9" Grid.Column="2" Grid.ColumnSpan="4" ItemsSource="{Binding}" />
    
                        <!-- Row 10 -->
                        <Button Name="btnDefaultClear"          Grid.Row="10" Grid.Column="0" Grid.ColumnSpan="2" Content="Start Over" Width="Auto" />
                        <ProgressBar Name="pb"                  Grid.Row="10" Grid.Column="2" Grid.ColumnSpan="2" HorizontalAlignment="Center" />
                        <!-- Commented Out Alternative Solution Which is Not Working Either -->
                        <!-- <Label Name="lblDefaultProcessing"      Grid.Row="10" Grid.Column="2" Grid.ColumnSpan="2" HorizontalAlignment="Center" /> -->
                        <Button Name="btnDefaultSearch"         Grid.Row="10" Grid.Column="4" Grid.ColumnSpan="2" Content="Go" Width="Auto" /> 
                        
                        <StackPanel Grid.Row="10" Grid.Column="6" Orientation="Horizontal" HorizontalAlignment="Left">
                            <Label Name="lblDefaultRecordsReturned" Width="Auto" />
                            <Button Name="btnDefaultSaveExcel"      Width="Auto" />
                            <Label Name="lblDefaultStatusBar"       Width="Auto" />
                        </StackPanel>
                        
                        <!-- Row 11 -->
                        <ScrollViewer Grid.Row="11" Grid.Column="0" Grid.ColumnSpan="8" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                            <DataGrid Name="dgDefault"          ItemsSource="{Binding}" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"/>
                        </ScrollViewer>
                    
                    </Grid>
                </TabItem>

  6. #6
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Cannot seem to change Progress Bar properties or visibility in WPF / VB.Net

    Did you set the style on the progress bar to Marquee?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2019
    Posts
    5

    Re: Cannot seem to change Progress Bar properties or visibility in WPF / VB.Net

    No. I didn't even know of that property for the progress bar. I may have figured it out. When non-ui processes are mixed in with ui-updates, everything seems to run synchronously. I think if I put all my db retrieval in a backgroundworker and use the progress updates, I might be able to get things working. That was my mistake. I'm used to writing automation packages that do not even have a user interface. I will verify later today. Thanks

  8. #8
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Cannot seem to change Progress Bar properties or visibility in WPF / VB.Net

    I think if I put all my db retrieval in a backgroundworker and use the progress updates.
    Yes, that would be the solution. The db related tasks should be on a separate thread(BackgroundWorker or Task).

    - kgc
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width