Gif Animation is not working as expected in WPF - wpf

I am having one multi thread WPF application. In that application am using gif image with one of the threads. I need to check whether database connection is established or not ,until then the icon should be loading gif, after that which will turn into success or failure icon accordingly.
I have used the following code to set the gif initially .
<Image x:Name="sample" Grid.Row="1" gif:ImageBehavior.AnimatedSource="{Binding DataBaseImageSource}" Margin="{Binding ElementName=BorderContainer, Path=Margin}" />
After that i am changing the icon using below code. This code will get executed after window.show() method.
try
{
myContext.Database.Connection.Open();
myContext.Database.Connection.Close();
this.DataBaseImageSource = (BitmapImage)Application.Current.FindResource("SuccessIcon");
}
catch (SqlException e)
{
this.ResultSummary = "Failure";
this.DataBaseSummary = e.Message.ToString();
this.DataBaseImageSource = (BitmapImage)Application.Current.FindResource("ErrorIcon");
return false;
}
return true;
once i called this above window.show() method, then am changing the animated source based on the database availability .
But the gif is not at all loading it behaves like a normal png image, after that the image gets changed based on the result. how can i make gif to be animated followed by source change?

Related

Codename One: How to increase height of dialog

I have developed app using Codename one.I want to set specific height of dialog because my text overidden while displaying message in dialog body .what should I do for that?
Thanks in Advance?
I have added image in which first image is original image and second one is cut image which is displaying on screen while using infinite progress bar. my code is "Dialog ipDialog = new InfiniteProgress().showInifiniteBlocking(); ipDialog.Dispose()" I want whole image on screen like original image.
can you help me to solved this ?
You can use the Dialog show method that accepts int values to determine the distance from the edges. But normally this is a matter of the text sizing and dialog construction.
Also make sure you are showing the Dialog from the EDT thread.

WPF - Display combination of contents(images, video, text)

I’m trying to display contents. Contents can be a combination of image, video & text. Each one of them has a start date time & end date time.
I could display one image using tag but I couldn’t display series of images in a loop. Its displaying only last image or video. Immediate help appreciated.
Code snippet as follows -
// Check if Content if its an Image
if (dataTable.Rows[nCnt][1].Equals("I"))
{
imageSource = new BitmapImage(new Uri(strContent));
Image1.Visibility = Visibility.Visible;
Image1.Source = imageSource;
}
else
// Check if Content if its an Video
if (dataTable.Rows[nCnt][1].Equals("V"))
{
MyVideo1.Source = new Uri(strContent);
MyVideo1.Visibility = Visibility.Visible;
MyVideo1.Play();
}
You are filling the same image and video container(Image1, MyVideo1), with diferent images and videos. So the last one is the only one displayed. You should create a collection of images and videos. List<YourMediaType> or ObservableCollection<YourMediaType> if you are using MVVM.

Tiny image size when adding an image to a button from an imagelist in c#

I am trying to show an image within a button using an ImageList, however when I run the code the image is being shown as a tiny 10x10 image. The actual size of the image is 193x261
Here is how I add the image to the list
ImageList imageList = new ImageList();
try
{
imageList.Images.Add(Image.FromFile(Directory.GetCurrentDirectory() + #"\Images\Phone.png"));
}
catch (Exception ex) { MessageBox.Show(ex.ToString()); }
and here is how I add the image to the button
call.BackgroundImage = imageList.Images[0];
call.BackgroundImageLayout = ImageLayout.Center;
I forgot to mention, the button is called 'call', the size of the button is 120x110.
Try this:
imageList.ImageSize = new Size(call.Width, call.Height);
It sets the image list size to that of the button (its parent container).

WebView is always the topmost component

I'm developing a reporting dashboard application using W8 Metro UI style application. The application has a dark theme, so most of the screen is black. I'm using the WebView control to display SSRS .rdl reports from our report server (which all have black backgrounds). The problem I'm seeing is that when I navigate to a new report, the WebView control flashes white for a split second and then loads the new report. To get around this, I tried putting an Easing opacity animation on the WebView control to make it fade out, load the report, and then fade back in. However, no matter what I try, I can't get the flickering to go away.
I then tried putting a black rectangle on top of the WebView and fading that one in and out... still no luck. The WebView is always on top at runtime, meaning I can't put any control on top of it. Does anyone know of a way around this?
I breifly looked into the WebView.Transitions, but couldn't find many resources on this. Could this be my answer?
EDIT:
Event to load the new report:
void ItemListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// Create a WebViewBrush of the content currently loaded in the WebView
WebViewBrush b = new WebViewBrush();
b.SourceName = "WebView1";
b.Redraw();
Rectangle1.Fill = b;
// Hide the WebView
WebView1.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
// Navigate to the new report
var selectedItem = ItemListView.SelectedItem;
WebView1.Navigate(((Report)selectedItem).ReportUri);
}
void WebView1_LoadCompleted(object sender, Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
// Show the new report
WebView1.Visibility = Windows.UI.Xaml.Visibility.Visible;
Rectangle1.Fill = new SolidColorBrush(Colors.Transparent);
}
This is just the way WebView works because internally its loading the trident COM control into a separate hwnd. The workaround is to set Visibility to Hidden on the webview and instead show a webviewbrush which isn't interactive but does integrate with the rest of your UI so it can be animated, etc

wp7 hyperlinks not visible

RTM version of the developer tools.
I am building an app. In parts of the app I have some text provided by a web service, I take this text and process it to make the URLs in the text act as hyperlinks.
The container for this is a wrap panel.
<wrap:WrapPanel x:Name="PostMessage2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
Then in the constructor of the page I have this simple code.
PostMessage2.Children.Add(new HyperlinkButton()
{
Content = new TextBlock()
{
Text = "test url",
Foreground = new SolidColorBrush(Colors.White)
},
NavigateUri = new Uri("http://www.google.com/")
});
(I know this code is will not open an IE session and navigate to the Url)
Now when I run this program, I will not see anything visible on the screen, but if I tap the screen where the start of the url should be, then it will try to navigate to the url (which causes an exception as the navigation isn't handled correctly).
If I add a Textblock before and after the URL the test in those blocks is visible, and they will be separated by approximately 3 spaces, which if you tap the middle of this it will try to navigate to the url.
So my question is why are the hyper-links not visible but they are active as you can tap them, am I missing some obvious property or setting?
Thanks in advance for help.
You don't need to set the Content of the HyperlinkButton to be a TextBlock. It's expecting a string and you can set the Foreground color on the HLB:
PostMessage2.Children.Add(new HyperlinkButton()
{
Content = "test url",
Foreground = new SolidColorBrush(Colors.White),
NavigateUri = new Uri("http://www.google.com/")
});

Resources