# VBForums CodeBank > CodeBank - Other >  WPFisms: Tips, Tricks, and Changes from WinForms

## DeanMc

Ok so the idea of this thread is to list all the little changes that could cause frustration when people are moving from WinForms to WPF. There are also some tips and tricks that are too small to be added to the code bank. Please post if you have any more and I will add them to the list.


Note: If you have a code example to add to your WPFism post it below if it is short. If it is a full tutorial or rather large please post in the code bank and I will link to it. If you are unsure PM me the example and I will help you decide where it should go. The idea is to keep the requests to the moderators to move posts about to a minimum, thanks guys! 
Control Tips, Tricks and Examples:

Where is my GridView?
WPF does not have a gridview by default. One can be downloaded from codeplex (see my sig). I do encourage you to not bother though. In WPF the listbox is now the powerhouse control. This is due to the fact that not only can you style a listbox to fit your data needs but you can also style each individual list item differently too. Styles are a major part of being a successful WPF designer so please take the time to learn them. Chris128 has posted a great alternative here. Submitted By Chris128

What happened to the Timer component?
Instead of using the normal Windows.Forms.Timer component, you now use the DispatcherTimer class. See code sample below. Submitted By Chris128

VB Code:
'Declare our timer at class level
Private WithEvents MyTimer As New System.Windows.Threading.DispatcherTimer
       
'Window_Loaded event - Very similar to the Form_Load event in winforms
Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
      'Set the timer to tick every 3 seconds
     MyTimer.Interval = TimeSpan.FromSeconds(3)
     'Could alternatively use MyTimer.IsEnabled = True
     MyTimer.Start()
 End Sub
       
'Our timer's tick event. This gets raised every 3 seconds in this example
Private Sub MyTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyTimer.Tick
      Button1.IsEnabled = Not Button1.IsEnabled 'Just something to do.. enabled/disable a button
 End Sub

How do I change a progress bar to use the Marquee animation style?
As the progressbar control in WPF has no Style property like it did in Winforms, you can set the property named "IsIndeterminate" to True to make the progressbar use a continuous marquee style animation. Submitted By Chris128

Why does the Button control have no Enabled property?
You now use the IsEnabled property instead. Submitted By Chris128

What happened to the ListViewSubItem class?
You don't need it as you just bind your listview to a public collection and then specify which column should display which property of the items in your collection. Submitted By Chris128

How can I change the colour of selected items in a listbox?
As the ListBox in WPF can be used for so many things, you will often find that you don't want the default blue background to appear whenever you click on an item. To change this you need to override the standard Highlight Brush in your own Style. Then you can set your listbox to use this style for its items by setting the ItemContainerStyle to that style, code example below. Submitted by Chris128


```
<Style x:Key="TransparentHighlightStyle" TargetType="ListBoxItem">
     <Style.Resources> 
         <SolidColorBrush x:Key=" {x:StaticSystemColors.HighlightBrushKey}"Color="Transparent"/>
     </Style.Resources> 

     <!---Rest of your Style Triggers/Setters etc go here-->
</Style>
```


General Tips, Tricks and Examples:

How do I remove the min/max buttons from a window?
These propeties have been merged in WPF to the Window.ResizeMode property. This property takes an enumeration and the values can be: NoResize, CanResize, CanResizeWithGrip and CanMinimize. I trust you will find every thing you need with those values. Submited By DeanMc

Are pixels till the unit of measurement in WPF?
No. Pixels have been dropped in favour of DIU or device independent units. The idea of this is that your application will look the same at different resolutions. The standard PC/Laptop resolution is 96DPI and consequently the size of one DIU is 1/96th of an inch, so while you will technically not be developing in pixels you can treat 1 DIU as one pixel for most users of your application. Submitted By DeanMc




Quirks, Bugs and Fixes:

3:I got a runtime error when I renamed my window?
This is because the StartUp URI in the application.xaml file needs to be change to match the new name of your window. See my blog post for detailed walk through and video example. Submitted By DeanMc

----------


## chris128

UPDATE: Added a third part to my DataGrid/ListView tutorial, this third part focuses on extending the existing control we built in the first two parts so that it now uses TextBoxes to contain each of its items instead of just un-editable text. This way we can let the user edit the data by typing in to the item textboxes and it will automatically update our collection in the code-behind.

----------

