WPF - how to display a loadable message for web browser control

I have a window with 2 columns. The left column contains the browser control

I would like to show a small window or something to show that the web page is still loading.

How can i do this? Can I have a floating window in the second column that is displayed in front of the browser ??? please explain how?

Malcolm

Thanks, bendwey works like a charm. The only thing is, can't find a GIF that I could use to show something moving / rotating or similar to overlay any ideas where?

+1


source to share


4 answers


The way I did it, create a custom control with Show () and Hide () methods public. Below is the code. Loading.xaml:

<UserControl x:Class="UK.Budgeting.XBAP.Loading"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="200">
  <UserControl.Resources>
    <Color x:Key="FilledColor" A="255" B="155" R="155" G="155"/>
    <Color x:Key="UnfilledColor" A="0" B="155" R="155" G="155"/>

    <Storyboard x:Key="Animation0" FillBehavior="Stop" BeginTime="00:00:00.0" RepeatBehavior="Forever">
      <ColorAnimationUsingKeyFrames Storyboard.TargetName="_00" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
        <SplineColorKeyFrame KeyTime="00:00:00.0" Value="{StaticResource FilledColor}"/>
        <SplineColorKeyFrame KeyTime="00:00:01.6" Value="{StaticResource UnfilledColor}"/>
      </ColorAnimationUsingKeyFrames>
    </Storyboard>

    <Storyboard x:Key="Animation1" BeginTime="00:00:00.2" RepeatBehavior="Forever">
      <ColorAnimationUsingKeyFrames Storyboard.TargetName="_01" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
        <SplineColorKeyFrame KeyTime="00:00:00.0" Value="{StaticResource FilledColor}"/>
        <SplineColorKeyFrame KeyTime="00:00:01.6" Value="{StaticResource UnfilledColor}"/>
      </ColorAnimationUsingKeyFrames>
    </Storyboard>

    <Storyboard x:Key="Animation2" BeginTime="00:00:00.4" RepeatBehavior="Forever">
      <ColorAnimationUsingKeyFrames Storyboard.TargetName="_02" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
        <SplineColorKeyFrame KeyTime="00:00:00.0" Value="{StaticResource FilledColor}"/>
        <SplineColorKeyFrame KeyTime="00:00:01.6" Value="{StaticResource UnfilledColor}"/>
      </ColorAnimationUsingKeyFrames>
    </Storyboard>

    <Storyboard x:Key="Animation3" BeginTime="00:00:00.6" RepeatBehavior="Forever">
      <ColorAnimationUsingKeyFrames Storyboard.TargetName="_03" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
        <SplineColorKeyFrame KeyTime="00:00:00.0" Value="{StaticResource FilledColor}"/>
        <SplineColorKeyFrame KeyTime="00:00:01.6" Value="{StaticResource UnfilledColor}"/>
      </ColorAnimationUsingKeyFrames>
    </Storyboard>

    <Storyboard x:Key="Animation4" BeginTime="00:00:00.8" RepeatBehavior="Forever">
      <ColorAnimationUsingKeyFrames Storyboard.TargetName="_04" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
        <SplineColorKeyFrame KeyTime="00:00:00.0" Value="{StaticResource FilledColor}"/>
        <SplineColorKeyFrame KeyTime="00:00:01.6" Value="{StaticResource UnfilledColor}"/>
      </ColorAnimationUsingKeyFrames>
    </Storyboard>

    <Storyboard x:Key="Animation5" BeginTime="00:00:01.0" RepeatBehavior="Forever">
      <ColorAnimationUsingKeyFrames Storyboard.TargetName="_05" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
        <SplineColorKeyFrame KeyTime="00:00:00.0" Value="{StaticResource FilledColor}"/>
        <SplineColorKeyFrame KeyTime="00:00:01.6" Value="{StaticResource UnfilledColor}"/>
      </ColorAnimationUsingKeyFrames>
    </Storyboard>

    <Storyboard x:Key="Animation6" BeginTime="00:00:01.2" RepeatBehavior="Forever">
      <ColorAnimationUsingKeyFrames Storyboard.TargetName="_06" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
        <SplineColorKeyFrame KeyTime="00:00:00.0" Value="{StaticResource FilledColor}"/>
        <SplineColorKeyFrame KeyTime="00:00:01.6" Value="{StaticResource UnfilledColor}"/>
      </ColorAnimationUsingKeyFrames>
    </Storyboard>

    <Storyboard x:Key="Animation7" BeginTime="00:00:01.4" RepeatBehavior="Forever">
      <ColorAnimationUsingKeyFrames Storyboard.TargetName="_07" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
        <SplineColorKeyFrame KeyTime="00:00:00.0" Value="{StaticResource FilledColor}"/>
        <SplineColorKeyFrame KeyTime="00:00:01.6" Value="{StaticResource UnfilledColor}"/>
      </ColorAnimationUsingKeyFrames>
    </Storyboard>
  </UserControl.Resources>

  <UserControl.Triggers>
    <EventTrigger RoutedEvent="FrameworkElement.Loaded">
      <BeginStoryboard Storyboard="{StaticResource Animation0}"/>
      <BeginStoryboard Storyboard="{StaticResource Animation1}"/>
      <BeginStoryboard Storyboard="{StaticResource Animation2}"/>
      <BeginStoryboard Storyboard="{StaticResource Animation3}"/>
      <BeginStoryboard Storyboard="{StaticResource Animation4}"/>
      <BeginStoryboard Storyboard="{StaticResource Animation5}"/>
      <BeginStoryboard Storyboard="{StaticResource Animation6}"/>
      <BeginStoryboard Storyboard="{StaticResource Animation7}"/>
    </EventTrigger>
  </UserControl.Triggers>

  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="*"/>
      <RowDefinition Height="100"/>
      <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*"/>
      <ColumnDefinition Width="Auto"/>
      <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Canvas Grid.Row="1" Grid.Column="1" Height="105" Width="105">
      <Canvas.Resources>
        <Style TargetType="Ellipse">
          <Setter Property="Width" Value="15"/>
          <Setter Property="Height" Value="15" />
          <Setter Property="Fill" Value="#FFFFFFFF" />
        </Style>
      </Canvas.Resources>
      <Ellipse x:Name="_00" Canvas.Left="24.75" Canvas.Top="50"/>
      <Ellipse x:Name="_01" Canvas.Top="36" Canvas.Left="29.5"/>
      <Ellipse x:Name="_02" Canvas.Left="43.5" Canvas.Top="29.75"/>
      <Ellipse x:Name="_03" Canvas.Left="57.75" Canvas.Top="35.75"/>
      <Ellipse x:Name="_04" Canvas.Left="63.5" Canvas.Top="49.75" />
      <Ellipse x:Name="_05" Canvas.Left="57.75" Canvas.Top="63.5"/>
      <Ellipse x:Name="_06" Canvas.Left="43.75" Canvas.Top="68.75"/>
      <Ellipse x:Name="_07" Canvas.Top="63.25" Canvas.Left="30" />
      <Ellipse Stroke="{x:Null}" Width="39.5" Height="39.5" Canvas.Left="31.75" Canvas.Top="37" Fill="{x:Null}"/>
    </Canvas>
    <TextBlock Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Foreground="#AAA" TextAlignment="Center" FontSize="15" Text="{Binding Source={StaticResource Model}, Path=StatusMessage}"/>
  </Grid>

</UserControl>

      

Loading.xaml.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace UK.Budgeting.XBAP
{
    /// <summary>
    /// Interaction logic for Loading.xaml
    /// </summary>
    public partial class Loading : UserControl
    {
        public Loading()
        {
            InitializeComponent();
        }
        public void Show()
        {
            this.Visibility = Visibility.Visible;
        }
        public void Hide()
        {
            this.Visibility = Visibility.Hidden;
        }
    }
}

      



To use, make a link on the home page:

<local:Loading x:Name="LoadingAnimation" Visibility="Hidden" />

      

and call from code:

LoadingAnimation.Show();
LoadingAnimation.Hide();

      

+3


source


I'm not sure what you mean by showing the "small window". you mean a popup or an element that appears on top of the browser, like an overlay. If you mean the overlay element, you can use the webbrowser Navigating and LoadCompleted events to show and hide the element.

There are several ways to position an element, depending on the parent control. If you are using a Grid control, just place a loading element under the browser control and it will appear on top when it becomes visible.



Several things to indicate when controls are overlaid. Simply changing the opacity to 0 won't work, you'll need to hide the visibility, otherwise your events in your browser won't fire. Also keep in mind that if you have a property to fade out / use the animation you will have to clear. See Josh Smits' post .

When replying, just change the original message. You may want to add your XAML to explain your plan.

+2


source


I found the gif creator.

The only thing the gif doesn't move is when the browser loads.

I am guessing this is a threading issue.

How do you do it?

0


source


Thanks for the posts.

I figured out of course I don't need GIF only WPF animation.

So, I just did a rotatetransform on the gif image I found.

Works like a charm

0


source







All Articles