Pausing/Stopping Gif animation in WPF - c#

I am using gif animation in WPF application, an external dll WpfAnimatedGif.dll is used for showing the animation. The animation is working properly, but I am unable to pause/stop it on a certain event let say button click, how can I do it, kindly guide me, my xaml code is given below
<Image x:Name="scaner" Stretch="UniformToFill" gif:ImageBehavior.AnimatedSource="{StaticResource gifImage}" >

According to your documentation (which you should have read yourself) this will work:
private void Button_Click(object sender, RoutedEventArgs e)
{
var controller = ImageBehavior.GetAnimationController(this.scaner);
controller.Pause();
}
Please note that working directly with button functions is not the prefered way in WPF, if you want to use the full power I suggest using MVVM and the command pattern instead.

You can try this, use reference
xamlAnimationWpf Nuget <br>
var controller = AnimationBehavior.GetAnimator(myGif); <br>
controller.Pause();<br>
For those who try another way

Related

Using two different events to update a ViewModel property in WPF

I apologize if the question title isn't really specific, I'm not exactly sure how to condense the problem I'm having down to a few words. But to simplifiy the problem I'm having, here is my issue:
I'm creating a tool using WPF that consists of a TextBox that will contain a path to a directory and a Button that will allow you to Browse to a certain directory. Now, when I select the Browse button, it pops up a dialog, allows the user to select a directory and then I have some methods that will disable some buttons and updates some Brushes on the screen if the path doesn't meet a certain set of criteria. No problems there, got that working.
My problem is the TextBox that this Browse button correlates with. This TextBox is using a binding as such:
In my MainWindow.xaml (Yes, this is the simplified, focused version):
<Window>
<TextBox Text="{Binding Directory}" TextChanged="Directory_TextChanged" />
<Button Content="Browse..." Click="Browse_Click"/>
</Window>
In my code MainWindow.xaml.cs file:
public partial class MainWindow: Window
{
private ViewModel myViewModel;
public MainWindow()
{
myViewModel = new ViewModel();
this.DataContext = myViewModel;
}
private void Browse_Click(object sender, RoutedEventArgs e)
{
// Dialog stuff that's working
viewModel.Directory = dialog.SelectedPath;
}
private void InstallDir_TextChanged(object sender, TextChangedEventArgs e)
{
ValidatePath(); /* Disables/enables buttons and updates brushes based on validation. Also working */
}
private void ValidatePath() {/* */}
}
Like I mentioned earlier, the browse button works fine. I'm trying to figure out however, how I can get this to work if I type a directory alongside it. Because if I type something in the textbox, that would mean that inside of the InstallDir_TextChanged() function I would have to set viewModel.Directory, but since I have the INotifyPropertyChanged attached to this ViewModel, this function would get called recursively.
I tried doing the validation stuff within the viewmodel, but I couldn't figure out how to update the brushes/buttons in MainWindow if I did this. (Still relatively new to C# so I haven't learned the ins and outs yet. This is the first WPF tool I've been making from scratch, so just a disclaimer).
Would anyone have any ideas (or logic) I can approach to try and accomplish this? If there's any further clarification needed, that's not an issue. I don't need an exact definitive answer. Maybe some advice that could point me in the correct direction would definitely suffice. I don't have a problem trying to figure stuff out.

Whats wrong with my code? Any reference missing?

I have been trying to add the navigation tool that will simply zoom in and zoom out. Push left and right using the click of the mouse.
I'm using in the Silverlight, Visual Studio 2010.
The XAML file contains the following:
<esri:Navigation Margin="5" HorizontalAlignment="Right" VerticalAlignment="Bottom"
Map="{Binding ElementName=MyMap}">
</esri:Navigation>
The C# file contains the following:
private void MyMap(object sender, RoutedEventArgs e)
{
MyMap.Focus();
}
I have added the reference dll file : ESRI.ArcGIS.Client.Toolkit
Though the navigator is visible on the map. But unable to function. Please assist the same.
I'm not sure what your MyMap(object, RoutedEventArgs) method is supposed to do, but MyMap needs to be the name of an esri:Map in your XAML file, not a method name. This blog post has a good simple example near the start.

C# Showing Buttons on taskbar thumbnails

In WMP, I have been shown buttons on the taskbar thumbnail. How can I make them for my winforms app in C#?
The WindowsAPICodePack contains a control called ThumbnailToolBarButton that you can use to get this functionality going.
You'll need to make sure you have icons for each of the buttons (as I don't believe you can put text on them), and then it should be a simple matter of creating new controls and adding relevant event handlers.
Sourced from here.
XAML
<Window.TaskbarItemInfo>
<TaskbarItemInfo>
<TaskbarItemInfo.ThumbButtonInfos>
<ThumbButtonInfo ImageSource="/IconProgressDemo;component/Icon1.ico" Description="Play!" Click="ThumbButtonInfo_Click" />
<ThumbButtonInfo ImageSource="/IconProgressDemo;component/Icon2.ico" Description="Stop!" Click="ThumbButtonInfo_Click" />
</TaskbarItemInfo.ThumbButtonInfos>
</TaskbarItemInfo>
</Window.TaskbarItemInfo>
C#
private void ThumbButtonInfo_Click(object sender, EventArgs e)
{
MessageBox.Show((sender as System.Windows.Shell.ThumbButtonInfo).Description);
}
I haven't tried this hope this will be helpful.
and refer these links.
http://www.zayko.net/post/Adding-Buttons-to-Window-Thumbnail-in-WPF-4-for-Windows-7-(C).aspx
http://msdn.microsoft.com/en-us/windows7trainingcourse_win7taskbarmanaged_topic2.aspx
http://msdn.microsoft.com/en-us/magazine/dd942846.aspx
and there is Taskbar API available you can try with that.

Multiple XAML layouts in WPF

App I am trying to create in WPF/C# has quite a few buttons in a layout with a "TV screen" type panel above (its actually an FMS emulator for commercial aircraft). Many of the buttons change the layout, which are numerous TEXTBOXs on the tv screen. My question is: is there a provision to encapsulate the layouts in different classes/files and load them into the "tv screen" at the selection of the various buttons? In other words, user hits the Flight Plan button and the layout of the 355x355 box (screen) above loads the XAML "flight_plan" layout/file/class. Each layout has different TEXTBOX sizes & locations and there are in excess of 30 different "pages", which would make encapsulating them desirable.
I am very new to WPF and c#, but have written win apps in c++ all the way back to Turbo C & OWL. I also may be trying to do something that isn't possible due to working lately in Android/Java and am confusing capabilities.
Thanks in advance.
Edit
Thanks to #adityaswami89 and everyone else who got me on the right track, I have found the solution. I added the pages via a new "WPF Page" in VS2012. Then changed the "screen" to a navigation frame and it was truly simple from there. Below is the simple project I created to test it.
public partial class MainWindow : Window
{
NavRad navrad = new NavRad();
FPlan fplan = new FPlan();
public MainWindow() {..}
private void Frame_Navigated_1(object sender, NavigationEventArgs e) {..}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Screen_Frame.Navigate(fplan);
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
Screen_Frame.Navigate(navrad);
}
You can also use the concept of Frames for the intended functionality , if that can be an option you are looking.
You can refer the below link for the same.
http://msdn.microsoft.com/en-us/library/ms750478.aspx#Frame_in_Standalone_Applications
You can abstract the different UI Layout Sets within different User Controls and load them according your UI logic. One way to do this is using an MVVM framework, for example, Caliburn Micro makes this a pretty simple task as doing:
ActivateItem(UILayoutViewModel);
And this call can be called from any method.
See more of Caliburn Screens and Composition at official source.

Autopopulate textboxes in Sieble CRM system, trough webBrowser1 in c#

Do any have any experience how this cold be done, if you look at the image im looking for a solution to programacly change the Name field to somehing else stored inn a variable from a other textbox.
i was thinking of using something like
private void button1_Click(object sender, EventArgs e)
{
var xBox = textbox1.value;
webBrowser1.Document.All.GetElementsByName("Name")[0].SetAttribute("Value", xBox);
}
but i dont know the name of the Textbox, and Sieble seems to be a java thing? so i cant see the source behind it? does anyone know how to solve this issue. im making a automate app to help at work for handeling over 100 cases a day. Instead of typing the names, im looking for a solution to populate by the click of a button.
I cant handel this by the sieble API because we dont have contorle of the Siebel develompent, and wold take years to get the Sieble department to implement somthing like this in to the GUI. so im making a desktop app that can handel the issue.
Sounds like you need to just search through the html (manually) until you find the names/ids of the fields you need to set.
Also, if the site supports Firefox, try using Firebug. In Firebug's inspect mode you can mouse over a text field and get the id of it.
My solution to this was using cordinates, and simulate keys klicks, im using Global Mouse and Keyboard Library for this, found at this location http://www.codeproject.com/KB/system/globalmousekeyboardlib.aspx
private void button1_Click(object sender, EventArgs e)
{
this.Location = new Point(0, 0);
inputBlocker();
xX = int.Parse(this.Location.X.ToString());
yY = int.Parse(this.Location.Y.ToString());
defaultMousePos();
//Thread.Sleep(600);
Cursor.Position = new Point(Cursor.Position.X + 1185, Cursor.Position.Y + 254);
//Thread.Sleep(600);
MouseSimulator.DoubleClick(MouseButton.Left);
KeyboardSimulator.KeyPress(Keys.T);
KeyboardSimulator.KeyPress(Keys.E);
KeyboardSimulator.KeyPress(Keys.S);
KeyboardSimulator.KeyPress(Keys.T);
KeyboardSimulator.KeyPress(Keys.O);
KeyboardSimulator.KeyPress(Keys.K);
KeyboardSimulator.KeyPress(Keys.Enter);
needUnblock = true;
inputBlocker();
}
#Darkmage - Is this a winforms application ?.If so did you not have any issues with loading the siebel activeX controls in the .NET webroswer control?

Categories

Resources