Geeks With Blogs

News



Add to Google

Tim Hibbard CEO for EnGraph software WPF
WPF TimeSpinner Control
As I discussed in my last post, we created a TimeSpinner control based on the Extended WPF Toolkit’s ButtonSpinner. Now, the toolkit has a DateTimeUpDown control that will display a date or time and allow the user to click the spinners for each time part, but I needed a little more. I needed the raw text to be editable and I wanted the spinners to just modify the minutes portion. I also wanted to have special parsing based on the number of characters entered. 4 chars:Parse as military time. 3 chars: ......

Posted On Thursday, April 14, 2011 10:16 AM

Smarter DateTime.AddMinutes
Our software will automatically generate pick up and drop off times based on distance of trip, how many other people are on the bus, how long it takes to drop them off, etc. We display these times in our custom TimeSpinner control based on WPF Extended Toolkit’s button spinner. Since the computer is generating the time, they are often not human-friendly. 6:00 AM is a lot easier to remember than 6:03 AM. So we give the users the option to modify these times. Using the spinners, they can adjust the ......

Posted On Tuesday, April 12, 2011 8:26 AM

WPF - Changing the content of a ToggleButton when checked
I don't think the WPF ToogleButton has a distinct visual difference between it's checked and unchecked state. So I wanted to change the text displayed when the button was checked. So I created a trigger that looked at the IsChecked property and changed the content property accordingly. However, the default template of a ToggleButton changes it's appearance when it is checked, so certain properties are not written as expected. To fix this, I set the content property in the styles of the toggle button ......

Posted On Tuesday, May 13, 2008 11:54 AM

WPF–Show Dialog with backdrop
Sometimes it handy to force the user’s attention to a specific screen. We can do this with a dialog, but sometimes the user doesn’t know that window is on top. To draw the user’s eye to the window, I like to place a backdrop between the rest of the application and the dialog window. I use the following code to make that happen. 1: public bool? ShowDialogWithBackdrop(Window win) 2: { 3: //create backgroup 4: Window backgroundWindow = new Window(); 5: backgroundWindow.Top = 0; 6: backgroundWindow.Left ......

Posted On Friday, April 8, 2011 9:17 AM

The last couple months of our life via twitter
Pre-approval letter in hand, let the house shopping begin!10:10 AM Apr 28th Apparently it's impossible to look at a house without the realtor begging to be your buyer's agent. Back off people!1:36 PM Apr 30th Finally going live with software that I've been working on for 2+ years!3:59 PM Apr 30th First install and we run into a proxy brick wall...smooth4:43 PM Apr 30th Done with an exhausting day of house hunting. Found a lot that we liked. One that we LOVED, in shawnee of all places.6:40 PM May ......

Posted On Friday, July 17, 2009 10:51 AM

Simple class to parse Twitter with LINQ
In ParaPlan 4.0, we use twitter to maintain a change log. I wanted to display this information to our users, so I wrote a little class that calls the RSS feed and uses LINQ to parse the data. All I need is the message and the date, so that is all it pulls out. Here is the class: public class Twitter { public string Message { get; set; } public DateTime PubDate { get; set; } public static List<Twitter> Parse(string User) { var rv = new List<Twitter>(); var url = "http://twitter.com/statuse... ......

Posted On Monday, January 5, 2009 2:53 PM

WPF – Hide a listbox when it doesn’t have any items
This code example will show how to hide a listbox from the user when it doesn’t have any items. It involves binding the Visibility of the listbox to the Items.Count of the listbox. We run the Items.Count through a converter that will return a Visibility.Visible object if the Item.Count is not zero. Here is the converter class: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Data; using System.Windows; namespace HideAListBox { public class ......

Posted On Tuesday, December 9, 2008 3:48 PM

WPF - Using SystemColors to add color to ListBox
Using colors is a simple way make your application less boring. You can change the color of the selected and unselected item in a ListBox by using code like this: <Style TargetType="ListBoxItem"> <Style.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrush... Color="LightGreen"/> <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="LightBlue"/> </Style.Resources> </Style> This style can be put in the resources of the ListBox ......

Posted On Tuesday, November 11, 2008 4:41 PM

WPF Custom Control Dependency Property Gotcha
Let's say you have a custom WPF control called SearchTextBox. It has a textbox and a button labeled "search". Simple enough, you reuse it in your application when you want to provide search. Then one day, you decide you need this control needs to be bindable. So you expose a public property Text and map it to textSearch just like you would in WinForms. Well, that doesn't work, so you google around and stumble upon Dependency Properties and learn how to create your own (VS snippet shortcut propdb) ......

Posted On Tuesday, April 22, 2008 1:11 AM

WPF - Get ListBoxItem from ListBox.SelectedItem
I had some trouble today getting the actual control that hosts data in a WPF listbox. The magic class is ListBox.ItemContainerGenerator used like this:MyStateObject current = this.myListBox.SelectedItem as MyStateObject; ListBoxItem lbi = this.myListBox.ItemContaine... as ListBoxItem; lbi.Margin = new Thickness(10); Technorati tags: WPF, C#, ListBox, ItemContainerGenerator ......

Posted On Wednesday, February 13, 2008 2:01 PM

WPF - Show/Hide element based on CheckBox.Checked
A lot of times, I need to show or hide a textbox based the value of a checkbox. In WinForms 2.0. This was easy: myTextBox.Visible = myCheckBox.Checked; With the new Visibility Enum in WPF, this becomes a bit trickier. To accomplish this, you need to implement a converter that will accept a boolean value and return a visibility value. The converter I used is here: using System; using System.Collections.Generic; using System.Text; using System.Windows.Data; using System.Windows; namespace ParaPlan.Converters ......

Posted On Monday, December 10, 2007 11:24 AM

WPF - TextBox.SelectAll
I think that any business application should select all the text in a TextBox when the user tabs into it. Your advanced users that take advantage of the tab key will appreciate it. In WinForms 2.0, the best way of accomplishing this was to create a new control that inherited from TextBox that implemented SelectAll functionality and use your new control instead of the normal TextBox. In WPF, this is much easier. In the App.xaml.cs, override the OnStartup method and use the EventManager.RegisterClassH... ......

Posted On Tuesday, September 18, 2007 8:29 AM

Real world desktop WPF applications - UI Validation
Intro to this series of posts. Some of the code I use for UI validation came from Paul Stovell, who is working on a WPF Element that acts like WinForms 2.0 ErrorProvider control. Paul's control didn't quite fit my needs, so I've tweaked a few things so I can provide visual validation in a generic fashion from my base class. All of our objects implement:Public Event InvalidProperty(string PropertyName, string ErrorMessage);Public Event Validated(object sender);Public bool IsValid; Our objects also ......

Posted On Thursday, July 19, 2007 11:39 AM

WPF Access Keys
In WPF, access keys are created like this:_Click Me! Pre-WPF was:&Click Me! Access keys in buttons work differently based on the type of control your text is rendered in. This code will only bring the keyboard focus to the button, it will not generate a click event: <Button Click="clickMeClick">_Click Me!</Button> When the user presses Alt - C on their keyboard, they expect the button to act as if it has been clicked, not just selected. To set keyboard focus and generate a click event, ......

Posted On Tuesday, August 28, 2007 10:15 AM

Real world desktop WPF applications - Data binding
Intro to this series of posts. There are a ton of posts out there about data binding with INotifyPropertyChanged objects in WPF, so I won't regurgitate what other people have already written. There is one point that I haven't see much clear documentation about that I would like to cover. Hosting data bound custom controls. Let's say we have a location control that is bound to a location object like so: <TextBox Text="{Binding Path=Address1}"/> <TextBox Text="{Binding Path=Address2}"/> ......

Posted On Monday, July 16, 2007 12:03 PM

Real world desktop WPF applications
The last month or so, I've been wallowing in Windows Presentation Foundation (WPF), trying to determine if it is the correct direction for our next version of our flagship software, ParaPlan. WPF is flashy and fun and bubbly, but there are not many examples of real world enterprise applications that are built around WPF. After much research, and significantly pushing back our deployment timeline, we decided to rebuild ParaPlan 4.0 using WPF for our UI. We were able to use our existing 2.0 UI framework ......

Posted On Sunday, July 15, 2007 10:52 PM

Copyright © Tim Hibbard | Powered by: GeeksWithBlogs.net