I\'m currently making a game (in vb.net) that uses the Graphics class to draw most of the game objects, but i\'ve run into the old problem of performance. To combat the lagging
I have made a sample WPF project similar to what you need, just to give you an idea how powerful and beautiful and fast WPF is compared to ancient technologies.
It looks like this:
It's a little too much code to post it here entirely, so here is a link to a RAR file with the full source.
The main UI XAML is this:
<Window x:Class="SamsGameSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SamsGameSample"
Title="SamsGameSample"
PreviewKeyDown="Window_PreviewKeyDown"
PreviewKeyUp="Window_PreviewKeyUp"
SizeChanged="Window_SizeChanged"
WindowState="Maximized">
<Window.Resources>
<DataTemplate DataType="{x:Type local:Player}">
<Ellipse Fill="Green" Stroke="Black" Height="{Binding Size.Height}" Width="{Binding Size.Width}"/>
</DataTemplate>
<DataTemplate DataType="{x:Type local:Enemy}">
<Ellipse Fill="Red" Stroke="Black" Height="{Binding Size.Height}" Width="{Binding Size.Width}"/>
</DataTemplate>
</Window.Resources>
<DockPanel>
<DockPanel.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0" Opacity=".6">
<GradientStop Color="Blue" Offset="0"/>
<GradientStop Color="Red" Offset=".5"/>
<GradientStop Color="Green" Offset="1"/>
</LinearGradientBrush>
</DockPanel.Background>
<StackPanel Orientation="Horizontal" Background="#70000000" DockPanel.Dock="Top">
<TextBlock Text="{Binding Lives, StringFormat='Lives: {0}'}" Margin="10" Foreground="AliceBlue"/>
<TextBlock Text="{Binding Score, StringFormat='Score: {0}'}" Margin="10" Foreground="AliceBlue"/>
</StackPanel>
<ItemsControl ItemsSource="{Binding GameObjects}" x:Name="GameArea">
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding Location.X}"/>
<Setter Property="Canvas.Top" Value="{Binding Location.Y}"/>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas IsItemsHost="True"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DockPanel>
</Window>