Search Results

Search found 8544 results on 342 pages for 'wpf navigation'.

Page 4/342 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Retaining expanded/contracted nodes in Word 2010's navigation pane

    - by msorens
    I have a lengthy document in Word 2010 which makes copious use of standard header styles. These display hierarchically (and very usefully!) in the navigation pane. But the list of these sections and subsections in the navigation pane is somewhat lengthy, with all nodes being expanded by default. I am now working near the end of the document so every time I open the document I contract the first so many header 1 nodes to compress the list to fit on one screen. I then have direct access to the later sections while still letting me access the earlier sections if needed. The problem is that as soon as I close the document all the customization I did in the navigation pane is lost. Is there any option or setting somewhere that will retain the expanded or contracted state of nodes in the navigation pane?

    Read the article

  • What is the WPF equivilant for the FlowLayoutPanel?

    - by Sargola
    I am working on a WPF application (a one note clone which is called "note your life") where you can dynamically assign Tags to an entry (just as in virtually any web 2.0 app these days). for this I had in my windows forms prototype a FlowLayoutPanel that did the job very well. I want to have the tags float to the next line if there isn't enough space and get a scrollbar if needed. how can this be achieved with WPF? I played around with <StackPanel Orientation="Horizontal" FlowDirection="LeftToRight" ...> but this doesn't move the elements in the next line if needed. Any suggestions?

    Read the article

  • Best aproach for multi-page WPF application

    - by 0xDEAD BEEF
    How do i create multislide application in WPF? What is beast approach? What i need is something very similar to having tabcontrol with multiple pages and navigation buttons bellow, but i dont think that tab control is best for this task. I would like to have each view to be in seperate .xaml + class file. AND- it would be cool to have some animiation, when navigating to another page (like old page slides away or something like that. What would be best technique to achieve this?

    Read the article

  • forcing Validation; WPF, DataGrid, ObservableCollection

    - by Steve Mills
    I have a WPF DataGrid. I read a csv file and build an ObservableCollection of objects. I set the DataGrid.ItemsSource to the Collection. I would like to then force a RowValidation on every row in the DataGrid. If I, playing user, edit a cell, the RowValidation fires, all is well. But the Validation does not fire on the initial load. Is there some way I can call ??ValidateRow?? on a row? on every row? (C#, WPF, VS2008, etc)

    Read the article

  • Winform custom control in WPF

    - by Erika
    Hi, I'm inserting a custom winform control in a WPF/ XAML window, however i'm realising that the sizing seems to be very different, what i designed in winform to be 730pixels wide for instance, when placed via a WindowsFormsHost, in a container 730pixels (or at least i think they're pixels..) wide, the control looks much larger and doesnt fit in the host and results in clipping from the right and bottom. Would anyone know how to make these sizes match or something? I'm really at a loss and its very difficult to fix a custom control to make it look as it should off hand on WPF! Please help!

    Read the article

  • wpf trigger events after a few milli-seconds!!!

    - by Rev
    Hi What was that "wpf trigger events after a few Milli-seconds" ;) Let me explain about that: I have a wpf form with few controls. some of these control over-writing template. for example a textblock with an effect will be trigger on Mouse-Enter event and change color of foreground to something else. But after running program when mouse enter on textBloc, it takes a few Milli-seconds until Mouse-enter event triggers. also all control or better say all control which use mouse-events have this problem. How solve this problem???

    Read the article

  • WPF Localization Using LocBaml: Handling Special Symbols

    - by Aryeh
    Hello, I’m dealing with localization of a WPF application (Visual Studio 2010 under Windows 7). I’ve just accomplished the whole process of localization using LocBaml tool, as explained in WPF Globalization and Localization Overview and in related posts. The target language is Italian (it-IT culture). When I run my application in Italian, I have a problem with interpretation of the special symbols of © and ™: they both appear there as a white question sign upon a black diamond-shaped background. The symbols © and ™ appear identically in both English and Italian CSV-files. I tried also the special letters (such as È, à etc.) that are present in Italian but absent in English, and they also are interpreted as the above diamond-shaped question. In Region and Language, I changed the system locale to Italian[Italy], restarted the PC and ran the application again – this helped me in the past to cope with a similar problem in localization of C++ applications under Windows XP, but now it didn’t help, either. Has somebody any idea what is the catch here?

    Read the article

  • HttpWebRequest socket operation during WPF binding in a property getter

    - by wpfwannabe
    In a property getter of a C# class I am doing a HTTP GET using HttpWebRequest to some https address. WPF's property binding seems to choke on this. If I try to access the property in a simple method e.g. Button_Clicked, it works perfectly. If I use WPF binding to access the same property, the app seems to be blocked on a socket's recv() method indefinitely. Is it a no-no to do this sort of thing during binding? Is app in some special state during binding? Is there an easy way for me to overcome this limitation and still maintain the same basic idea?

    Read the article

  • WPF (irc) chat log control

    - by user408952
    I'm trying to learn WPF and was thinking about creating a simple IRC client. The most complicated part is to create the chat log. I want it to look more or less like the one in mIRC: or irssi: The important parts are that the text should be selectable, lines should wrap and it should be able to handle quite large logs. The alternatives that I can come up with are: StackPanel inside a ScrollViewer where each line is a row ListView, since that seems more suitable for dynamic content/data binding. Create an own control that does the rendering on its own. Is there any WPF guru out there that has some ideas on which direction to take and where to start?

    Read the article

  • How different is WPF from ASP.NET [closed]

    - by Tom
    I have been quickly moved over to a different project at work because the project needs more help. I was chosen because they are confident in my abilities and they thought I would be best fit for the next couple weeks to help finish the application out. I am a little nervous. I do tend to pick things up quickly. I was moved to a different project at the beginning of this year and now I know it like the back of my hand. Previously I was on another project. Both of these projects were an ASP.NET web application, which I believe is considered a winforms web application? The project I am moving to is a desktop WPF application. I have read that many people enjoy developing their applications with WPF. I just have never dealt/worked with WPF before. I like to consider myself pretty good at ASP.NET/C# and I do a solid job. We deal with a lot of data processing from the database and report generation. So I do get to experience C# more so than some web applications where the C# end of it is mostly just event driven and simple instructions. How different are the two? Will it be completely foreign to me? Or is it just a different way of looking at a problem and I can familiarize myself quickly? Thanks for the input.

    Read the article

  • Navigate between screens in WPF

    - by Greg R
    This should be a very basic design question, but for some reason it doesn't seem to be well documented (maybe due to its simplicity?). If I'm building a dashboard application in WPF that brig up different CRM tasks and I want to navigate between screens, is this the best way to do this, or is there a better way? So for example I have Log In Screen - Main Menu Screen - Screen to one of different utilities var orderManagerWindow = new MyXamlView(); var loginWindow = Application.Current.MainWindow; orderManagerWindow.Left = loginWindow.Left; orderManagerWindow.Top = loginWindow.Top; Application.Current.MainWindow = orderManagerWindow; orderManagerWindow.Show(); loginWindow.Close(); I would really appreciate help and suggestions!

    Read the article

  • Navigation (controller) in Tabbar (c) in Navigation (c) (iphone)

    - by Jonathan
    I want to have a TabBar controller inside a navigation controller. So that when an item is selected on the first Navigation Controller it pushes the TabBar into view. Inside this tabbar on the first tab is another navigation controller. However I only want one navigation bar. I've come up with 2 ways but not sure which way is better (Ie more acceptable etc)? 1) The first navigation controller isn't actually a navigation controller but to the user it looks like one. So when a cell is selected on it's table view the first navC's view is removed from the superview and the TabBarC's view is added, animation would have to be done manually. 2)The first NavC is actually a NavC and when an item is selected and the TabBar is pushed on to the screen the first NavC's navigationbar is hidden so that the first tab's navigationBar is the only nav bar on screen.

    Read the article

  • ParallelWork: Feature rich multithreaded fluent task execution library for WPF

    - by oazabir
    ParallelWork is an open source free helper class that lets you run multiple work in parallel threads, get success, failure and progress update on the WPF UI thread, wait for work to complete, abort all work (in case of shutdown), queue work to run after certain time, chain parallel work one after another. It’s more convenient than using .NET’s BackgroundWorker because you don’t have to declare one component per work, nor do you need to declare event handlers to receive notification and carry additional data through private variables. You can safely pass objects produced from different thread to the success callback. Moreover, you can wait for work to complete before you do certain operation and you can abort all parallel work while they are in-flight. If you are building highly responsive WPF UI where you have to carry out multiple job in parallel yet want full control over those parallel jobs completion and cancellation, then the ParallelWork library is the right solution for you. I am using the ParallelWork library in my PlantUmlEditor project, which is a free open source UML editor built on WPF. You can see some realistic use of the ParallelWork library there. Moreover, the test project comes with 400 lines of Behavior Driven Development flavored tests, that confirms it really does what it says it does. The source code of the library is part of the “Utilities” project in PlantUmlEditor source code hosted at Google Code. The library comes in two flavors, one is the ParallelWork static class, which has a collection of static methods that you can call. Another is the Start class, which is a fluent wrapper over the ParallelWork class to make it more readable and aesthetically pleasing code. ParallelWork allows you to start work immediately on separate thread or you can queue a work to start after some duration. You can start an immediate work in a new thread using the following methods: void StartNow(Action doWork, Action onComplete) void StartNow(Action doWork, Action onComplete, Action<Exception> failed) For example, ParallelWork.StartNow(() => { workStartedAt = DateTime.Now; Thread.Sleep(howLongWorkTakes); }, () => { workEndedAt = DateTime.Now; }); Or you can use the fluent way Start.Work: Start.Work(() => { workStartedAt = DateTime.Now; Thread.Sleep(howLongWorkTakes); }) .OnComplete(() => { workCompletedAt = DateTime.Now; }) .Run(); Besides simple execution of work on a parallel thread, you can have the parallel thread produce some object and then pass it to the success callback by using these overloads: void StartNow<T>(Func<T> doWork, Action<T> onComplete) void StartNow<T>(Func<T> doWork, Action<T> onComplete, Action<Exception> fail) For example, ParallelWork.StartNow<Dictionary<string, string>>( () => { test = new Dictionary<string,string>(); test.Add("test", "test"); return test; }, (result) => { Assert.True(result.ContainsKey("test")); }); Or, the fluent way: Start<Dictionary<string, string>>.Work(() => { test = new Dictionary<string, string>(); test.Add("test", "test"); return test; }) .OnComplete((result) => { Assert.True(result.ContainsKey("test")); }) .Run(); You can also start a work to happen after some time using these methods: DispatcherTimer StartAfter(Action onComplete, TimeSpan duration) DispatcherTimer StartAfter(Action doWork,Action onComplete,TimeSpan duration) You can use this to perform some timed operation on the UI thread, as well as perform some operation in separate thread after some time. ParallelWork.StartAfter( () => { workStartedAt = DateTime.Now; Thread.Sleep(howLongWorkTakes); }, () => { workCompletedAt = DateTime.Now; }, waitDuration); Or, the fluent way: Start.Work(() => { workStartedAt = DateTime.Now; Thread.Sleep(howLongWorkTakes); }) .OnComplete(() => { workCompletedAt = DateTime.Now; }) .RunAfter(waitDuration);   There are several overloads of these functions to have a exception callback for handling exceptions or get progress update from background thread while work is in progress. For example, I use it in my PlantUmlEditor to perform background update of the application. // Check if there's a newer version of the app Start<bool>.Work(() => { return UpdateChecker.HasUpdate(Settings.Default.DownloadUrl); }) .OnComplete((hasUpdate) => { if (hasUpdate) { if (MessageBox.Show(Window.GetWindow(me), "There's a newer version available. Do you want to download and install?", "New version available", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { ParallelWork.StartNow(() => { var tempPath = System.IO.Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Settings.Default.SetupExeName); UpdateChecker.DownloadLatestUpdate(Settings.Default.DownloadUrl, tempPath); }, () => { }, (x) => { MessageBox.Show(Window.GetWindow(me), "Download failed. When you run next time, it will try downloading again.", "Download failed", MessageBoxButton.OK, MessageBoxImage.Warning); }); } } }) .OnException((x) => { MessageBox.Show(Window.GetWindow(me), x.Message, "Download failed", MessageBoxButton.OK, MessageBoxImage.Exclamation); }); The above code shows you how to get exception callbacks on the UI thread so that you can take necessary actions on the UI. Moreover, it shows how you can chain two parallel works to happen one after another. Sometimes you want to do some parallel work when user does some activity on the UI. For example, you might want to save file in an editor while user is typing every 10 second. In such case, you need to make sure you don’t start another parallel work every 10 seconds while a work is already queued. You need to make sure you start a new work only when there’s no other background work going on. Here’s how you can do it: private void ContentEditor_TextChanged(object sender, EventArgs e) { if (!ParallelWork.IsAnyWorkRunning()) { ParallelWork.StartAfter(SaveAndRefreshDiagram, TimeSpan.FromSeconds(10)); } } If you want to shutdown your application and want to make sure no parallel work is going on, then you can call the StopAll() method. ParallelWork.StopAll(); If you want to wait for parallel works to complete without a timeout, then you can call the WaitForAllWork(TimeSpan timeout). It will block the current thread until the all parallel work completes or the timeout period elapses. result = ParallelWork.WaitForAllWork(TimeSpan.FromSeconds(1)); The result is true, if all parallel work completed. If it’s false, then the timeout period elapsed and all parallel work did not complete. For details how this library is built and how it works, please read the following codeproject article: ParallelWork: Feature rich multithreaded fluent task execution library for WPF http://www.codeproject.com/KB/WPF/parallelwork.aspx If you like the article, please vote for me.

    Read the article

  • Split WPF Style XAML Files

    - by anon
    Most WPF styles I have seen are split up into one very long Theme.xaml file. I want to split mine up for readability so my Theme.xaml looks like this: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/PresentationFramework.Aero;v3.0.0.0;31bf3856ad364e35;component/themes/aero.normalcolor.xaml"/> <ResourceDictionary Source="Controls/Brushes.xaml"/> <ResourceDictionary Source="Controls/Buttons.xaml"/> ... </ResourceDictionary.MergedDictionaries> </ResourceDictionary> The problem is that this solution does not work. I have a default button style which is BasedOn the default Aero style for a button: <Style x:Key="{x:Type Button}" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}"> <Setter Property="FontSize" Value="14"/> ... </Style> If I place all of this in one file it works but as soon as I split it up I get StackOverflow exceptions because it thinks it is BasedOn itself. Is there a way around this? How does WPF add resources when merging resource dictionaries?

    Read the article

  • WPF Control validation

    - by Jon
    Hi all, I'm developing a WPF GUI framework and have had bad experiences with two way binding and lots of un-needed events being fire(mainly in Flex) so I have gone down the route of having bindings (string that represent object paths) in my controls. When a view is requested to be displayed the controller loads the view, and gets the needed entities (using the bindings) from the DB and populates the controls with the correct values. This has a number of advantages i.e. lazy loading, default undo behaviour etc. When the data in the view needs to be saved the view is passed back to the controller again which basically does the reserve i.e. re-populates the entities from the view if values have changed. However, I have run into problems when I try and validate the components. Each entity has attributes on its properties that define validation rules which the controller can access easily and validate the data from the view against it. The actual validation of data is fine. The problem comes when I want the GUI control to display error validation information. It I try changing the style I get errors saying styles cannot be changed once in use. Is the a way in c# to fire off the normal WPF validation mechanism and just proved it with the validaiton errors the controller has found? Thanks in advance Jon

    Read the article

  • General Question About WPF Control Behavior and using Invoke

    - by Phil Sandler
    I have been putting off activity on SO because my current reputation is "1337". :) This is a question of "why" and not "how". By default, it seems that WPF does not set focus to the first control in a window when it's opening. In addition, when a textbox gets focus, by default it does not have it's existing text selected. So basically when I open a window, I want focus on the first control of the window, and if that control is a textbox, I want it's existing text (if any) to be selected. I found some tips online to accomplish each of these behaviors, and combined them. The code below, which I placed in the constructor of my window, is what I came up with: Loaded += (sender, e) => { MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); var textBox = FocusManager.GetFocusedElement(this) as TextBox; if (textBox != null) { Action select = textBox.SelectAll; //for some reason this doesn't work without using invoke. Dispatcher.Invoke(DispatcherPriority.Loaded, select); } }; So, my question. Why does the above not work without using Dispatcher.Invoke? Is something built into the behavior of the window (or textbox) cause the selected text to be de-selected post-loading? Maybe related, maybe not--another example of where I had to use Dispatcher.Invoke to control the behavior of a form: http://stackoverflow.com/questions/2602979/wpf-focus-in-tab-control-content-when-new-tab-is-created

    Read the article

  • Aliasing Resources (WPF)

    - by Noldorin
    I am trying to alias a resource in XAML, as follows: <UserControl.Resources> <StaticResourceExtension x:Key="newName" ResourceKey="oldName"/> </UserControl.Resources> oldName simply refers to a resource of type Image, defined in App.xaml. As far as I understand, this is the correct way to do this, and should work fine. However, the XAML code gives me the superbly unhelpful error: "The application XAML file failed to load. Fix errors in the application XAML before opening other XAML files." This appears when I hover over the StaticResourceExtension line in the code (which has a squiggly underline). Several other errors are generated in the actual Error List, but seem to be fairly irrelevant and nonsenical (such messages as "The name 'InitializeComponent' does not exist in the current context"), as they all disappear when the line is removed. I'm completely stumped here. Why is WPF complaining about this code? Any ideas as to a resolution please? Note: I'm using WPF in .NET 3.5 SP1. Update 1: I should clairfy that I do receive compiler errors (the aforementioned messages in the Error List), so it's not just a designer problem. Update 2: Here's the relevant code in full... In App.xaml (under Application.Resource): <Image x:Key="bulletArrowUp" Source="Images/Icons/bullet_arrow_up.png" Stretch="None"/> <Image x:Key="bulletArrowDown" Source="Images/Icons/bullet_arrow_down.png" Stretch="None"/> And in MyUserControl.xaml (under UserControl.Resources): <StaticResourceExtension x:Key="columnHeaderSortUpImage" ResourceKey="bulletArrowUp"/> <StaticResourceExtension x:Key="columnHeaderSortDownImage" ResourceKey="bulletArrowDown"/> These are the lines that generate the errors, of course.

    Read the article

  • WPF Browser is there, but invisible.

    - by Adam Crossland
    I am attempting to use the Browser control in a very simple WPF application, and it appears that while the browser is loading the page that I requested (I can mouseover images and see the ALT tags), I can't actually see anything else: Here is the XAML for the app: <Window x:Class="SmokeyBox2.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="SmokeyBox" Height="120" Width="510" ShowInTaskbar="False" SizeToContent="WidthAndHeight" WindowStyle="None" AllowsTransparency="True" MouseLeftButtonDown="Window_MouseLeftButtonDown"> <Border Background="#50FFFFFF" CornerRadius="5" BorderThickness="2,0,2,2" Padding="5 1 5 5"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"></RowDefinition> <RowDefinition Height="Auto"></RowDefinition> <RowDefinition Height="Auto"></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"></ColumnDefinition> <ColumnDefinition Width="Auto"></ColumnDefinition> </Grid.ColumnDefinitions> <Label Grid.Row="0" Grid.Column="0" Background="Transparent" Content="SmokeyBox" MouseLeftButtonDown="Label_MouseLeftButtonDown" /> <TextBox Grid.Row="1" Grid.Column="0" Name="searchText" Width="450" FontFamily="Arial" Foreground="DarkGray" Background="Transparent" FontSize="20" MouseLeftButtonDown="searchText_MouseLeftButtonDown" BorderBrush="Transparent" /> <Expander Grid.Row="1" Grid.Column="1" Padding="2 3 0 0 " Expanded="Expander_Expanded" Collapsed="Expander_Collapsed" /> <WebBrowser Grid.Row="2" Grid.Column="0" x:Name="browser" Visibility="Visible" Width="480" Height="480" Margin="2 2 2 2" ></WebBrowser> </Grid> </Border> </Window> So can anyone help me figure out why the browser isn't showing the Yahoo! home page like I asked it to? And while I am at it, I'm going to own up to the fact that this is my first WPF app, and I'd love to hear any general pointers on how to get rid of general noobie badness in my XAML. Thanks.

    Read the article

  • WPF vs. WinForms - a Delphi programmer's perspective?

    - by Robert Oschler
    I have read most of the major threads on WPF vs. WinForms and I find myself stuck in the unfortunate ambivalence you can fall into when deciding between the tried and true previous tech (Winforms), and it's successor (WPF). I am a veteran Delphi programmer of many years that is finally making the jump to C#. My fellow Delphi programmers out there will understand that I am excited to know that Anders Hejlsberg, of Delphi fame, was the architect behind C#. I have a strong addiction to Delphi's VCL custom components, especially those involved in making multi-step Wizards and components that act as a container for child components. With that background, I am hoping that those of you that switched from Delphi to C# can help me with my WinForms vs. WPF decision for writing my initial applications. Note, I am very impatient when coding and things like full fledged auto-complete and proper debugger support can make or break a project for me, including being able to find readily available information on API features and calls and even more so, workarounds for bugs. The SO threads and comments in the early 2009 date range give me great concern over WPF when it comes to potential frustrations that could mar my C# UI development coding. On the other hand, spending an inordinate amount of time learning an API tech that is, even if it is not abandoned, soon to be replaced (WinForms), is equally troubling and I do find the GPU support in WPF tantalizing. Hence my ambivalence. Since I haven't learned either tech yet I have a rare opportunity to get a fresh start and not have to face the big "unlearning" curve I've seen people mention in various threads when a WinForms programmer makes the move to WPF. On the other hand, if using WPF will just be too frustrating or have other major negative consequences for an impatient RAD developer like myself, then I'll just stick with WinForms until WPF reaches the same level of support and ease of use. To give you a concrete example into my psychology as a programmer, I used VB and subsequently Delphi to completely avoid altogether the very real pain of coding with MFC, a Windows UI library that many developers suffered through while developing early Windows apps. I have never regretted my luck in avoiding MFC. It would also be comforting to know if Anders Hejlsberg had a hand in the architecture of WPF and/or WinForms, and if there are any disparities in the creative vision and ease of use embodied in either code base. Finally, for the Delphi programmers again, let me know how much "IDE schock" I'm in for when using WPF as opposed to WinForms, especially when it comes to debugger support. Any job market comments updated for 2011 would be appreciated too. -- roschler

    Read the article

  • WPF vs. WinForms - a Delphi programmer's perspective?

    - by Robert Oschler
    Hello all. I have read most of the major threads on WPF vs. WinForms and I find myself stuck in the unfortunate ambivalence you can fall into when deciding between the tried and true previous tech (Winforms), and it's successor (WPF). I am a veteran Delphi programmer of many years that is finally making the jump to C#. My fellow Delphi programmers out there will understand that I am excited to know that Anders Hejlsberg, of Delphi fame, was the architect behind C#. I have a strong addiction to Delphi's VCL custom components, especially those involved in making multi-step Wizards and components that act as a container for child components. With that background, I am hoping that those of you that switched from Delphi to C# can help me with my WinForms vs. WPF decision for writing my initial applications. Note, I am very impatient when coding and things like full fledged auto-complete and proper debugger support can make or break a project for me, including being able to find readily available information on API features and calls and even more so, workarounds for bugs. The SO threads and comments in the early 2009 date range give me great concern over WPF when it comes to potential frustrations that could mar my C# UI development coding. On the other hand, spending an inordinate amount of time learning an API tech that is, even if it is not abandoned, soon to be replaced (WinForms), is equally troubling and I do find the GPU support in WPF tantalizing. Hence my ambivalence. Since I haven't learned either tech yet I have a rare opportunity to get a fresh start and not have to face the big "unlearning" curve I've seen people mention in various threads when a WinForms programmer makes the move to WPF. On the other hand, if using WPF will just be too frustrating or have other major negative consequences for an impatient RAD developer like myself, then I'll just stick with WinForms until WPF reaches the same level of support and ease of use. To give you a concrete example into my psychology as a programmer, I used VB and subsequently Delphi to completely avoid altogether the very real pain of coding with MFC, a Windows UI library that many developers suffered through while developing early Windows apps. I have never regretted my luck in avoiding MFC. It would also be comforting to know if Anders Hejlsberg had a hand in the architecture of WPF and/or WinForms, and if there are any disparities in the creative vision and ease of use embodied in either code base. Finally, for the Delphi programmers again, let me know how much "IDE schock" I'm in for when using WPF as opposed to WinForms, especially when it comes to debugger support. Any job market comments updated for 2011 would be appreciated too. -- roschler

    Read the article

  • Detecting Idle Time with Global Mouse and Keyboard Hooks in WPF

    - by jdanforth
    Years and years ago I wrote this blog post about detecting if the user was idle or active at the keyboard (and mouse) using a global hook. Well that code was for .NET 2.0 and Windows Forms and for some reason I wanted to try the same in WPF and noticed that a few things around the keyboard and mouse hooks didn’t work as expected in the WPF environment. So I had to change a few things and here’s the code for it, working in .NET 4. I took the liberty and refactored a few things while at it and here’s the code now. I’m sure I will need it in the far future as well. using System; using System.Diagnostics; using System.Runtime.InteropServices; namespace Irm.Tim.Snapper.Util { public class ClientIdleHandler : IDisposable { public bool IsActive { get; set; } int _hHookKbd; int _hHookMouse; public delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam); public event HookProc MouseHookProcedure; public event HookProc KbdHookProcedure; //Use this function to install thread-specific hook. [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId); //Call this function to uninstall the hook. [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] public static extern bool UnhookWindowsHookEx(int idHook); //Use this function to pass the hook information to next hook procedure in chain. [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] public static extern int CallNextHookEx(int idHook, int nCode, IntPtr wParam, IntPtr lParam); //Use this hook to get the module handle, needed for WPF environment [DllImport("kernel32.dll", CharSet = CharSet.Auto)] public static extern IntPtr GetModuleHandle(string lpModuleName); public enum HookType : int { GlobalKeyboard = 13, GlobalMouse = 14 } public int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam) { //user is active, at least with the mouse IsActive = true; Debug.Print("Mouse active"); //just return the next hook return CallNextHookEx(_hHookMouse, nCode, wParam, lParam); } public int KbdHookProc(int nCode, IntPtr wParam, IntPtr lParam) { //user is active, at least with the keyboard IsActive = true; Debug.Print("Keyboard active"); //just return the next hook return CallNextHookEx(_hHookKbd, nCode, wParam, lParam); } public void Start() { using (var currentProcess = Process.GetCurrentProcess()) using (var mainModule = currentProcess.MainModule) { if (_hHookMouse == 0) { // Create an instance of HookProc. MouseHookProcedure = new HookProc(MouseHookProc); // Create an instance of HookProc. KbdHookProcedure = new HookProc(KbdHookProc); //register a global hook _hHookMouse = SetWindowsHookEx((int)HookType.GlobalMouse, MouseHookProcedure, GetModuleHandle(mainModule.ModuleName), 0); if (_hHookMouse == 0) { Close(); throw new ApplicationException("SetWindowsHookEx() failed for the mouse"); } } if (_hHookKbd == 0) { //register a global hook _hHookKbd = SetWindowsHookEx((int)HookType.GlobalKeyboard, KbdHookProcedure, GetModuleHandle(mainModule.ModuleName), 0); if (_hHookKbd == 0) { Close(); throw new ApplicationException("SetWindowsHookEx() failed for the keyboard"); } } } } public void Close() { if (_hHookMouse != 0) { bool ret = UnhookWindowsHookEx(_hHookMouse); if (ret == false) { throw new ApplicationException("UnhookWindowsHookEx() failed for the mouse"); } _hHookMouse = 0; } if (_hHookKbd != 0) { bool ret = UnhookWindowsHookEx(_hHookKbd); if (ret == false) { throw new ApplicationException("UnhookWindowsHookEx() failed for the keyboard"); } _hHookKbd = 0; } } #region IDisposable Members public void Dispose() { if (_hHookMouse != 0 || _hHookKbd != 0) Close(); } #endregion } } The way you use it is quite simple, for example in a WPF application with a simple Window and a TextBlock: <Window x:Class="WpfApplication2.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <TextBlock Name="IdleTextBox"/> </Grid> </Window> And in the code behind we wire up the ClientIdleHandler and a DispatcherTimer that ticks every second: public partial class MainWindow : Window { private DispatcherTimer _dispatcherTimer; private ClientIdleHandler _clientIdleHandler; public MainWindow() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { //start client idle hook _clientIdleHandler = new ClientIdleHandler(); _clientIdleHandler.Start(); //start timer _dispatcherTimer = new DispatcherTimer(); _dispatcherTimer.Tick += TimerTick; _dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 1); _dispatcherTimer.Start(); } private void TimerTick(object sender, EventArgs e) { if (_clientIdleHandler.IsActive) { IdleTextBox.Text = "Active"; //reset IsActive flag _clientIdleHandler.IsActive = false; } else IdleTextBox.Text = "Idle"; } } Remember to reset the ClientIdleHandle IsActive flag after a check.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >