Windows
Presentation
Foundation
Copyright © 2012 DAVID Holding Company
Въдведение

Copyright © 2012 DAVID Holding Company
Разделение
•
•
•
•
•

Разделение на интерфейса от управлението
Описване на интерфейса с XAML
За управлението се използват ...
Богата композиция
• Могат да се дефинират почти всички типове
контроли един в друг

Copyright © 2012 DAVID Holding Company
ДЕМО: Вграждане на контроли

Copyright © 2012 DAVID Holding Company
Независима резолюция
• Единиците за измерване не са в пиксели, а са
логически
• Ако увеличите резолюцията на екрана, интер...
ДЕМО: Създаване на първо приложение

Copyright © 2012 DAVID Holding Company
XAML
• Описателен език
• Базира се на XML
• Създава .NET обекти с йерархични връзки

Copyright © 2012 DAVID Holding Compan...
Предимства на XAML
• Кратък и лесен за четене
• Отделяне на дизайнерския код от логиката
• Позволява екипна работа на диза...
XAML или код
<StackPanel>
<TextBlock Margin="20">Welcome to XAML</TextBlock>
<Button Margin="10" HorizontalAlignment="Righ...
XAML или код
// Create the StackPanel
StackPanel stackPanel = new StackPanel();
this.Content = stackPanel;
// Create the T...
Свойствата като атрибути
<Button>
<Button.Content>
<Image Source="Images/OK.png"
Width="50"
Height="50" />
</Button.Conten...
Namespaces
<Window
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com...
Оформление
Най-разпространените контроли за оформление:
•
•
•
•
•

Grid Panel
Stack Panel
Dock Panel
Wrap Panel
Canvas Pan...
ДЕМО: Създаване на Grid Panel

Copyright © 2012 DAVID Holding Company
ДЕМО: Създаване на Stack Panel

Copyright © 2012 DAVID Holding Company
Вградени контроли
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•

DataGrid
Calendar
ItemsControl
LivePreview ComboBox
Dialogs
Slider
...
ДЕМО: Вградени контроли

Copyright © 2012 DAVID Holding Company
ДЕМО: Създаване на приложение за
разглеждане на снимки

Copyright © 2012 DAVID Holding Company
Upcoming SlideShare
Loading in …5
×

Курс по програмиране за напреднали (2012) - 5. Windows Presentation Foundation

400 views
284 views

Published on

Занятие №5 на курса по програмиране за напреднали (2012) провеждан от ДАВИД академия в гр.Казанлък. Включва темите:
- Windows Presentation Foundation

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
400
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • The Windows Presentation Foundation is Microsofts next generation UI framework to create applications with a rich user experience. It is part of the .NET framework 3.0 and higher.WPF combines application UIs, 2D graphics, 3D graphics, documents and multimedia into one single framework. Its vector based rendering engine uses hardware acceleration of modern graphic cards. This makes the UI faster, scalable and resolution independent.
  • WPF separates the appearance of an user interface from its behavior. The appearance is generally specified in the Extensible Application Markup Language (XAML), the behavior is implemented in a managed programming language like C# or Visual Basic. The two parts are tied together by databinding, events and commands. The separation of appearance and behavior brings the following benefits:Appearance and behaviour are loosely coupledDesigners and developers can work on separate models.Graphical design tools can work on simple XML documents instead of parsing code.
  • Controls in WPF are extremely composable. You can define almost any type of controls as content of another. Although these flexibility sounds horrible to designers, its a very powerful feature if you use it appropriate. Put an image into a button to create an image button, or put a list of videos into a combobox to choose a video file.
  • All measures in WPF are logical units - not pixels. A logical unit is a 1/96 of an inch. If you increase the resolution of your screen, the user interface stays the same size - it just gets crispier. Since WPF builds on a vector based rendering engine it&apos;s incredibly easy to build scaleable user interfaces.
  • All measures in WPF are logical units - not pixels. A logical unit is a 1/96 of an inch. If you increase the resolution of your screen, the user interface stays the same size - it just gets crispier. Since WPF builds on a vector based rendering engine it&apos;s incredibly easy to build scaleable user interfaces.
  • All measures in WPF are logical units - not pixels. A logical unit is a 1/96 of an inch. If you increase the resolution of your screen, the user interface stays the same size - it just gets crispier. Since WPF builds on a vector based rendering engine it&apos;s incredibly easy to build scaleable user interfaces.
  • XAML stands for Extensible Application Markup Language. Its a simple language based on XML to create and initialize .NET objects with hierarchical relations. Altough it was originally invented for WPF it can by used to create any kind of object trees.Today XAML is used to create user interfaces in WPF, Silverlight, declare workflows in WF and for electronic paper in the XPS standard.All classes in WPF have parameterless constructors and make excessive usage of properties. That is done to make it perfectly fit for XML languages like XAML.
  • All you can do in XAML can also be done in code. XAML ist just another way to create and initialize objects. You can use WPF without using XAML. It&apos;s up to you if you want to declare it in XAML or write it in code. Declare your UI in XAML has some advantages:XAML code is short and clear to readSeparation of designer code and logicGraphical design tools like Expression Blend require XAML as source.The separation of XAML and UI logic allows it to clearly separate the roles of designer and developer.
  • Properties are normally written inline as known from XML &lt;Button Content=&quot;OK&quot; /&gt;. But what if we want to put a more complex object as content like an image that has properties itself or maybe a whole grid panel? To do that we can use the property element syntax. This allows us to extract the property as an own child element.
  • At the beginning of every XAML file you need to include two namespaces. The first is http://schemas.microsoft.com/winfx/2006/xaml/presentation. It is mapped to all wpf controls inSystem.Windows.Controls. The second is http://schemas.microsoft.com/winfx/2006/xaml it is mapped to System.Windows.Markup that defines the XAML keywords.The mapping between an XML namespace and a CLR namespace is done by the XmlnsDefinition attribute at assembly level. You can also directly include a CLR namespace in XAML by using the clr-namespace: prefix.
  • Layout of controls is critical to an applications usability. Arranging controls based on fixed pixel coordinates may work for an limited enviroment, but as soon as you want to use it on different screen resolutions or with different font sizes it will fail. WPF provides a rich set built-in layout panels that help you to avoid the common pitfalls.
  • The StackPanel in WPF is a simple and useful layout panel. It stacks its child elements below or beside each other, dependening on its orientation. This is very useful to create any kinds of lists. All WPF ItemsControls like ComboBox,ListBox or Menu use a StackPanel as their internal layout panel.
  • Курс по програмиране за напреднали (2012) - 5. Windows Presentation Foundation

    1. 1. Windows Presentation Foundation Copyright © 2012 DAVID Holding Company
    2. 2. Въдведение Copyright © 2012 DAVID Holding Company
    3. 3. Разделение • • • • • Разделение на интерфейса от управлението Описване на интерфейса с XAML За управлението се използват езици като C# или Visual Basic Двете части се свързват с databinding, събития и команди Дизайнери и разработчици могат да работят заедно Copyright © 2012 DAVID Holding Company
    4. 4. Богата композиция • Могат да се дефинират почти всички типове контроли един в друг Copyright © 2012 DAVID Holding Company
    5. 5. ДЕМО: Вграждане на контроли Copyright © 2012 DAVID Holding Company
    6. 6. Независима резолюция • Единиците за измерване не са в пиксели, а са логически • Ако увеличите резолюцията на екрана, интерфейса остава същия размер Copyright © 2012 DAVID Holding Company
    7. 7. ДЕМО: Създаване на първо приложение Copyright © 2012 DAVID Holding Company
    8. 8. XAML • Описателен език • Базира се на XML • Създава .NET обекти с йерархични връзки Copyright © 2012 DAVID Holding Company
    9. 9. Предимства на XAML • Кратък и лесен за четене • Отделяне на дизайнерския код от логиката • Позволява екипна работа на дизайнери и разработчици Copyright © 2012 DAVID Holding Company
    10. 10. XAML или код <StackPanel> <TextBlock Margin="20">Welcome to XAML</TextBlock> <Button Margin="10" HorizontalAlignment="Right">OK</Button> </StackPanel> Copyright © 2012 DAVID Holding Company
    11. 11. XAML или код // Create the StackPanel StackPanel stackPanel = new StackPanel(); this.Content = stackPanel; // Create the TextBlock TextBlock textBlock = new TextBlock(); textBlock.Margin = new Thickness(10); textBlock.Text = "Welcome to the World of XAML"; stackPanel.Children.Add(textBlock); // Create the Button Button button = new Button(); button.Margin= new Thickness(20); button.Content = "OK"; stackPanel.Children.Add(button); Copyright © 2012 DAVID Holding Company
    12. 12. Свойствата като атрибути <Button> <Button.Content> <Image Source="Images/OK.png" Width="50" Height="50" /> </Button.Content> </Button> Copyright © 2012 DAVID Holding Company
    13. 13. Namespaces <Window xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”> </Window> Copyright © 2012 DAVID Holding Company
    14. 14. Оформление Най-разпространените контроли за оформление: • • • • • Grid Panel Stack Panel Dock Panel Wrap Panel Canvas Panel Copyright © 2012 DAVID Holding Company
    15. 15. ДЕМО: Създаване на Grid Panel Copyright © 2012 DAVID Holding Company
    16. 16. ДЕМО: Създаване на Stack Panel Copyright © 2012 DAVID Holding Company
    17. 17. Вградени контроли • • • • • • • • • • • • • • • • • • DataGrid Calendar ItemsControl LivePreview ComboBox Dialogs Slider Popup RadioButton ToolTips TextBox Menus Expander PasswordBox ContextMenu ListBox ListView TextBlock Window Copyright © 2012 DAVID Holding Company
    18. 18. ДЕМО: Вградени контроли Copyright © 2012 DAVID Holding Company
    19. 19. ДЕМО: Създаване на приложение за разглеждане на снимки Copyright © 2012 DAVID Holding Company

    ×