.NET 4.5 Infoday, Graz, November 8th 2012                                                      Rainer Stropek             ...
Overview   Ribbon   Performance improvements   Data Binding enhancements    Live shaping    Binding to static propertie...
.NET Infoday, Graz                              Ribbon                              System.Windows.Controls.Ribbon        ...
.NET Infoday, Graz<RibbonWindow …>  <Grid>                                                                 Ribbon    <Ribb...
.NET Infoday, Graz…<Window.Resources>                                                         Perf Improvements  <Collecti...
.NET Infoday, Graz <ListBox VirtualizingPanel.IsVirtualizing="True"  VirtualizingPanel.ScrollUnit="Pixel">                ...
.NET Infoday, Graz…<CollectionViewSource x:Key="LiveShapingViewSource"                                                    ...
.NET Infoday, Graz<TextBlock  Text="{Binding Path=(local:MainWindow.CurrentTickValue)}" />                                ...
.NET Infoday, Graz…                                            Data Binding<Slider Minimum="0" Maximum="100"  x:Name="Slid...
.NET Infoday, Graz                                            Async                                            Example: Re...
.NET Infoday, Grazprivate readonly ObservableCollection<string> strings =  new ObservableCollection<string>();            ...
.NET Infoday, Grazthis.Dispatcher.InvokeAsync(                     Async  () => /* manipulate UI here */);                ...
.NET Infoday, Graz<TextBox Text="{Binding Path=ValidationText}" />…                                                       ...
.NET 4.5 Infoday, Graz, November 8th 2012                                                      Rainer Stropek             ...
Upcoming SlideShare
Loading in …5
×

Whats New for WPF in .NET 4.5

2,004 views

Published on

This slide deck contains an overview about important enhancements regarding WPF that came with Microsoft .NET 4.5

Published in: Technology
  • Be the first to comment

Whats New for WPF in .NET 4.5

  1. 1. .NET 4.5 Infoday, Graz, November 8th 2012 Rainer Stropek software architects gmbhWPF Mail Web Twitter rainer@timecockpit.com http://www.timecockpit.com @rstropekWhat’s New in .NET 4.5? Saves the day.
  2. 2. Overview Ribbon Performance improvements Data Binding enhancements Live shaping Binding to static properties Delay changes to data source Better support for async programming Access to collections in non-UI threads INotifyDataErrorInfo API enhancements for Dispatcher For a complete list of all enhancements see MSDN
  3. 3. .NET Infoday, Graz Ribbon System.Windows.Controls.Ribbon (MSDN Link) Use Ribbon for WPF for previous versions of .NET (MS Download Link)RibbonBuilt-in ribbon in .NET 4.5
  4. 4. .NET Infoday, Graz<RibbonWindow …> <Grid> Ribbon <Ribbon …> <Ribbon.HelpPaneContent>…</Ribbon.HelpPaneContent> XAML Code Snippet <Ribbon.QuickAccessToolBar>…</Ribbon.QuickAccessToolBar> <Ribbon.ApplicationMenu>…</Ribbon.ApplicationMenu> <RibbonTab Header="Home" KeyTip="H" > <RibbonGroup … Header="Clipboard"> <RibbonMenuButton LargeImageSource="Imagesclipboard.png" Label="Paste" KeyTip="V"> … </RibbonGroup> </RibbonTab> </Ribbon> </Grid></RibbonWindow>
  5. 5. .NET Infoday, Graz…<Window.Resources> Perf Improvements <CollectionViewSource x:Key="ViewSource"> <CollectionViewSource.GroupDescriptions> Enable UI virtualization for <PropertyGroupDescription grouped data PropertyName="Nationality" /> Reduces time for initial rendering </CollectionViewSource.GroupDescriptions> and scrolling </CollectionViewSource></Window.Resources>…<DataGrid Control virtualizing cache using new CacheLength and ItemsSource="{Binding Source={StaticResource Src}}“ CacheLengthUnit properties VirtualizingPanel.IsVirtualizingWhenGrouping="True"> <DataGrid.GroupStyle> <x:Static Member="GroupStyle.Default"/> </DataGrid.GroupStyle></DataGrid>…
  6. 6. .NET Infoday, Graz <ListBox VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.ScrollUnit="Pixel"> Perf Improvements <ListBox.Items> <sys:String>Item 1</sys:String> Enable smooth scrolling in <sys:String>Item 2</sys:String> virtualizing panel using new ScrollUnit attached property … </ListBox.Items> <ListBox.ItemTemplate> <DataTemplate> <Border Height="100"> <TextBlock Text="{Binding}" /> </Border> </DataTemplate> </ListBox.ItemTemplate></ListBox>
  7. 7. .NET Infoday, Graz…<CollectionViewSource x:Key="LiveShapingViewSource" Live Shaping IsLiveSortingRequested="True"> <CollectionViewSource.SortDescriptions> Data in grouped/sorted/filtered <scm:SortDescription PropertyName="StockValue„ lists is automatically rearranged. Direction="Descending" /> </CollectionViewSource.SortDescriptions></CollectionViewSource>…<DataGrid ItemsSource="{Binding Source= {StaticResource LiveShapingViewSource}}" />…
  8. 8. .NET Infoday, Graz<TextBlock Text="{Binding Path=(local:MainWindow.CurrentTickValue)}" /> Data Binding…private static int currentTickValue; Problem: Change notification forpublic static int CurrentTickValue { static properties. INotifyPropertyChanged is get { no option return currentTickValue; } Solution in .NET 4.5: Add a static set { event handler currentTickValue = value; if (CurrentTickValueChanged != null) { CurrentTickValueChanged(null, new EventArgs()); } }}public static event EventHandler CurrentTickValueChanged;…
  9. 9. .NET Infoday, Graz… Data Binding<Slider Minimum="0" Maximum="100" x:Name="Slider" Width="300“ Use new Delay property to delay refresh of binding source Value="{Binding ElementName=SliderValue, Path=Text, Delay=1000, Mode=OneWayToSource}"/><TextBlock x:Name="SliderValue" />…
  10. 10. .NET Infoday, Graz Async Example: Retrieve data from database or webservice in a background threadAccess Collections in BackgroundThreadsProblem: Access only allowed in UI thread
  11. 11. .NET Infoday, Grazprivate readonly ObservableCollection<string> strings = new ObservableCollection<string>(); Asyncprivate readonly object stringsSyncObject = new object();… Enable modification of collections in background threads usingBindingOperations.EnableCollectionSynchronization( EnableCollectionSynchronization this.strings, this.stringsSyncObject);…var timer = new Timer(1000);timer.Start();timer.Elapsed += (___, ____) =>{ this.strings.Add(DateTime.Now.Ticks.ToString());};
  12. 12. .NET Infoday, Grazthis.Dispatcher.InvokeAsync( Async () => /* manipulate UI here */); New TPL-compatible API for WPF Dispatcherthis.Dispatcher.BeginInvoke( new Action(() => /* manipulate UI here */));
  13. 13. .NET Infoday, Graz<TextBox Text="{Binding Path=ValidationText}" />… Asyncpublic class MyViewModel : …, INotifyDataErrorInfo { private async void ValidateAsync() { INotifyDataErrorInfo var valid = await DoAsyncValidation(); enables async validation of data if (!valid) { Use this mechanism to keep UI if (this.ErrorsChanged != null) { responsive this.ErrorsChanged(this, new DataErrorsChangedEventArgs("ValidationText")); } } } public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged; public IEnumerable GetErrors(string propertyName) {…} public bool HasErrors {…}}
  14. 14. .NET 4.5 Infoday, Graz, November 8th 2012 Rainer Stropek software architects gmbh Mail rainer@timecockpit.comQ&A Web Twitter http://www.timecockpit.com @rstropekThank You For Coming. Saves the day.

×