Windows Presentation Foundation
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
3,796
On Slideshare
2,820
From Embeds
976
Number of Embeds
5

Actions

Shares
Downloads
28
Comments
0
Likes
0

Embeds 976

http://eastgroup.pl 966
http://www.eastgroup.pl 4
http://webcache.googleusercontent.com 3
http://www.slideshare.net 2
http://213.184.18.148 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Windows Presentation Foundation
    Dawid Cieszyńskicieszak@cieszak.eu
  • 2. Agenda
    Co to jest? Do czego służy?
    Porównanie z Windows Forms
    Język XAML i przykłady kodu
    Data Binding i Update Trigger
    Expression Blend
    Nowe kontrolki w WPF?
    Podsumowanie
  • 3. Co to jest?
    Windows Presentation Foundation
    (System.Windows.*)
    Windows CardSpace
    Windows Communication
    Foundation
    (System.ServiceModel.*)
    Windows Workflow Foundation
    (System.Workflow.*)
  • 4. Do czego służy?
  • 5. Co to jest?
    Nowa estetyka Windows Vista
    Transformacje, animacje, przezroczystość, cieniowanie, efekty trójwymiarowe, itp.
    Style
    Wyzwalacze
  • 6. WPF vs Windows Forms
  • 7. XAML
    C#
    VB.NET
    <Button Width="100"> OK
    <Button.Background>
    LightBlue
    </Button.Background>
    </Button>
    Button b1 = new Button();
    b1.Content = "OK";
    b1.Background = new SolidColorBrush(Colors.LightBlue);
    b1.Width = 100;
    Dim b1 As New Button
    b1.Content = "OK"
    b1.Background = New _SolidColorBrush(Colors.LightBlue)
    b1.Width = 100
    XAML = ExtensibleApplicationMarkupLanguage
    HTML?
  • 8. Przykłady kodu XAML
  • 9. App.xaml
    <Application x:Class="WpfApplication1.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="MainWindow.xaml">
    <Application.Resources>
    </Application.Resources>
    </Application>
  • 10. MainWindow.xaml
    <Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
    </Grid>
    </Window>
  • 11. Layout
    DockPanel
    StackPanel
    Grid
    Canvas
  • 12. Przykład XAML
    <Rectangle Fill="Red„Width="150„Height="100" />
  • 13. Przykład XAML
    <Grid ShowGridLines="True">
    <Grid.ColumnDefinitions>
    <ColumnDefinition />
    <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
    <RowDefinition/>
    <RowDefinition />
    </Grid.RowDefinitions>
    <Rectangle Fill="Red" Width="150" Height="100„Grid.Column="1"Grid.Row="1"/>
    </Grid>
  • 14. Przykład XAML
    <Button Height="25" Width="100"Grid.Column="0„Grid.Row="0" Click="Button_Click"/>
    <Rectangle x:Name="rect" Fill="Red"Width="150" Height="100"Grid.Column="1"Grid.Row="1"/>
    privatevoidButton_Click(object sender, RoutedEventArgs e)
    {
    rect.Fill= newSolidColorBrush(Colors.Blue);
    }
  • 15. Przykład XAML
    <Rectangle x:Name="rect" Width="150" Height="100"Grid.Column="1"Grid.Row="1">
    <Rectangle.Fill>
    <LinearGradientBrush>
    <GradientStop Offset="0" Color="LightBlue" />
    <GradientStop Offset="0.4" Color="Blue" />
    <GradientStop Offset="0.8" Color="Purple" />
    <GradientStop Offset="1.0" Color="Lavender"/>
    </LinearGradientBrush>
    </Rectangle.Fill>
    </Rectangle>
  • 16. Przykład XAML
    <TextBlockFontFamily="Verdana" FontSize="72„FontStyle="Italic" FontWeight="Bold" >
    KOALA
    <TextBlock.Foreground>
    <ImageBrushImageSource="Koala.jpg" />
    </TextBlock.Foreground>
    </TextBlock>
  • 17. Przykład XAML
    <TextBlock Text="Click to win!" TextDecorations="None"
    Cursor="Hand" FontSize="14" FontWeight="Bold"
    MouseEnter="TextBlock_MouseEnter"
    MouseLeave="TextBlock_MouseLeave"
    MouseLeftButtonUp="TextBlock_MouseLeftButtonUp" />
    privatevoidTextBlock_MouseEnter(object sender, MouseEventArgs e)
    {
    ((TextBlock)sender).TextDecorations = TextDecorations.Underline;
    ((TextBlock)sender).Foreground = Brushes.Maroon;
    }
    privatevoidTextBlock_MouseLeave(object sender, MouseEventArgs e)
    {
    ((TextBlock)sender).TextDecorations = null;
    ((TextBlock)sender).Foreground = Brushes.Black;
    }
    privatevoidTextBlock_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
    MessageBox.Show("Congratulations!");
    }
  • 18. Style
    <Application.Resources>
    <StyleTargetType="Button" x:Key="GelButton">
    <Setter Property="Margin" Value="1,2,1,2"/>
    <Setter Property="HorizontalAlignment„Value="Left"/>
    <Setter Property="Template">
    <Setter.Value>
    ...
    </Setter.Value>
    </Setter>
    </Style>
    </Application.Resources>
    <Button Height="50" Width="250" Style="{StaticResource GelButton}" Content="Button 1"/>
  • 19. Style
    <Application.Resources>
    <StyleTargetType="Button">
    <Setter Property="Margin" Value="1,2,1,2"/>
    <Setter Property="HorizontalAlignment„Value="Left"/>
    <Setter Property="Template">
    <Setter.Value>
    ...
    </Setter.Value>
    </Setter>
    </Style>
    </Application.Resources>
    <Button Height="50" Width="250"Content="Button 1"/>
  • 20. Data Binding
    Managed Object
    ADO.NET Data Source
    XML Data
  • 21. Data Binding
  • 22. Tryby Bindowania
    OneWay
    TwoWay
    OneWayToSource
    OneTime
    Cel
    Źródło
  • 23. Bindowanie do obiektu
    namespace MyNamespace
    {
    classMyClass
    {
    publicstring ColorName
    {
    get { return"Red"; }
    }
    }
    }<DockPanel xmlns:c="clr-namespace:MyNamespace">
    <DockPanel.Resources>
    <c:MyClass x:Key="mySource" />
    </DockPanel.Resources>
    <ButtonBackground="{Binding Path=ColorName,Source={StaticResourcemySource}}">
    ...
    </Button>
    </DockPanel>
  • 24. Bindowanie
    <DockPanel xmlns:c="clr-namespace:MyNamespace">
    <DockPanel.Resources>...</DockPanel.Resources>
    <DockPanel.DataContext>
    <Binding Source="{StaticResource mySource}"/>
    </DockPanel.DataContext>
    <Button Background="{Binding Path=BackColorName}">
    ...
    </Button>
    <TextBox Foreground="{Binding Path=ForeColorName}">
    ...
    </TextBox>
    </DockPanel>
  • 25. UpdateTrigger
    <TextBox Width="100">
    <TextBox.Text>
    <Binding Source="{StaticResource myData}"
    Path="ColorName"
    UpdateSourceTrigger="PropertyChanged" />
    </TextBox.Text>
    </TextBox>
    Kiedy ma następować aktualizacja?
  • UpdateTrigger - przykład
    <Label>Enter a Name:</Label>
    <TextBox>
    <TextBox.Text>
    <BindingSource="{StaticResource myDataSource}" Path="Name" UpdateSourceTrigger= "PropertyChanged" />
    </TextBox.Text>
    </TextBox>
    <Label>The name you entered:</Label>
    <TextBlock Text="{Binding Source= {StaticResourcemyDataSource}, Path = Name}"/><TextBox Name="itemNameTextBox" Text="{Binding Path=ItemName, UpdateSourceTrigger=Explicit}" />
    //itemNameTextBox is an instance of a TextBox
    BindingExpressionbe = itemNameTextBox.GetBindingExpression(TextBox.TextProperty);
    be.UpdateSource();
  • 29. DataTemplate
    <DataTemplate x:Key="myTaskTemplate">
    <Border Name="border" BorderBrush="Aqua" BorderThickness="1" Padding="5" Margin="5">
    <Grid>
    <Grid.RowDefinitions>
    <RowDefinition/>
    <RowDefinition/>
    <RowDefinition/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
    <ColumnDefinition />
    <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <TextBlockGrid.Row="0"Grid.Column="0" Text="Task Name:"/>
    <TextBlock Grid.Row="0" Grid.Column="l" Text="{BindingPath=TaskName}"/>
    <TextBlock Grid.Row="1" Grid.Column="0" Text="Description:" />
    <TextBlock Grid.Row="1"Grid.Column="1" Text="{Binding Path.Description}" />
    <TextBlock Grid.Row="2"Grid.Column="0"Text="Priority:" />
    <TextBlock Grid.Row="2" Grid.Column="1" Text="{BindingPath=Priority}" />
    </Grid>
    </Border>
    </DataTemplate><ListBox Width="400" Margin="10" ItemsSource="{Binding Source={StaticResource myTodoList}}"ItemTemplate="{StaticResource myTaskTemplate}" HorizontalContentAlignment="Stretch"/>
  • 30. <Border Width="400"
    BorderBrush="Green"
    BorderThickness="9">
    <StackPanel>
    <MediaElement Source="aero.wmv" />
    <Button>Hello</Button>
    </StackPanel>
    </Border>
    Audio i Wideo
    Ronnie Saurenmann (WPF)
    Różne formaty: WMV, MPEG, Some AVIs
    Synchronizacha z animacjami
  • 31. Grafika 2D, Grafika 3D, Obrazy
    Ronnie Saurenmann (WPF)
    Grafika 2D
    Grafika 3D
    Obrazy
  • 32. Transformacja i animacja
    RotateTransform
    ScaleTransform
    RenderTransform
    Efekty: rozmycie, poświata
    Zmiana każdej właściwości w czasie
  • 33. Dokumenty, drukowanie
    Użycie kontrolek Windows Forms
    XAML Browser Applications (XBAPs)
    Co jeszcze?
  • 34. Expression Blend
  • 35. Nowe kontrolki
    Datagrid, Ribbon, Visual State Manager
    WPF Toolkit:http://wpf.codeplex.com/
    Office UI Licensing Developer Center:
    http://msdn.microsoft.com/hr-hr/office/aa973809(en-us).aspx
  • 36. Demo
    Ribbon
  • 37. Łatwe tworzenie GUI
    Automagiczne przekazywanie wartości
    Prostota i funkcjonalność
    Oddzielenie logiki od wyglądu
    Zachwyt użytkownika
    Podsumowanie
  • 38. Dziękuję
    <Canvas Width="100" Height="100"><Ellipse Fill="Yellow" Stroke="Black"
    StrokeThickness="7"
    Width="100" Height="100" />
    <Ellipse Fill="Black"
    Width="10" Height="15"
    Canvas.Left="28" Canvas.Top="28" />
    <Ellipse Fill="Black"
    Width="10" Height="15"
    Canvas.Left="62" Canvas.Top="28" />
    <Path Stroke="Black"
    StrokeThickness="6"
    Data="M 30,60 Q 50,90 70,60" />
    </Canvas>