Вы находитесь на странице: 1из 21

"":www.intuit.

ru

4.WPF

WPF,
,,
.

,,
().,
.
,.
,,
,.
,.
WindowsWPF,
.
,
.
:,
,.
,,
.
.
ADO.NETEntityFramework
EDM(EntityDataModel).EDM
.

,
.TitlePresonal
,,
.
:
.
:

.
WPF(.4.1).""
.NETFramework4(1.4.1),
Windows(2.4.1),WPF""
WpfApplProject.
"".
XAML:
<Windowx:Class="WpfApplProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"Height="350"Width="525">
<Grid>

</Grid>
</Window>


.4.1.
.4.2.

.4.2.
XAML<Window>.
</Window>.XAMLMainWindow
x:Class="WpfApplProject.MainWindow

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
:

Title="MainWindow"Height="350"Width="525"
Window.
WPFMainWindow350525.
,.4.3.

.4.3.MainWindow
,XAML,
(MainWindow.xaml),CLR,
(MainWindow.xaml.cs).
InitializeComponent()
.
,XAML,
XAMLName.Grid
:
<GridName="grid">

</Grid>

,,.
WPF(),
.,XAML
,C#.
,
.
.WPF
:
NavigationWindow,Window
Frame,
Frame,InternetExplorer.
Frame(.4.4).
Frame(.4.5).


.4.4.Frame

.4.5.
XAML:
<FrameHeight="100"HorizontalAlignment="Left"
Name="frame1"VerticalAlignment="Top"Width="200"/>
,,
:
<FrameName="frame1"Margin="3"/>
(.4.6):


.4.6.,
WPF.Page
.
FrameworkElement.Page,
,
..
Page:
Background,
Content,.
(GridStackPanel)
Foreground,FontFamile,FontSize
..
WindowWidth,WindowHeight,(
,)
NavigationServiceNavigationService,

KeepAlive,

ShowsNavigationUI,

Title,
WindowTitle,.
.
WpfApplProject.(1.4.8),
(2.4.7).
"(WPF)"(1)
PageMain(2.4.8).


.4.7.

.4.8.
PageMain.xaml(.4.9).


.4.9.PageMain.xaml
Grid.Grid
StackPanel.
StackPanelBackground,
.,..:
<StackPanel.Background>
...
</StackPanel.Background>
System.Windows.Media.Brush
,.
:
LineaGradientBrush,,

RadialGradientBrush,,

ImageBrush,,,

DrawingBrush,Drawing,

VisualBrush,Visual.
.
LinearGradientBrush.
LinearGradientBrush.GradientStopsGradientStop.GradientStop
OffsetColor,"".
Offset01,
.

XAML.
<StackPanel.Background>
<LinearGradientBrush>
<LinearGradientBrush.GradientStops>
<GradientStopOffset="0.00"Color="#FF87A0DE"/>
<GradientStopOffset="0.50"Color="Azure"/>
<GradientStopOffset="1.00"Color="#FF009CFF"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</StackPanel.Background>
"".
<TextBlockMargin="25,30,25,5"FontSize="20">

</TextBlock>
.
Source,Foreground,BorderBrushBackground.
<FrameName="frame1"Margin="3"
Source="PageMain.xaml"
Foreground="#FFE4D8D8"
BorderBrush="#FFF7F3F3"
Background="#FFB3D9E5"/>
.4.10.

.4.10.WPF
TitleWindow,"".
WPF.4.11.

.4.11.WPF
StackPanel.
Background,,
,.,
,
,.
<Application.Resources>
<LinearGradientBrushx:Key="BackgroundWindowResource">

<GradientStopOffset="0.00"Color="#FF87A0DE"/>

<GradientStopOffset="0.50"Color="Azure"/>

<GradientStopOffset="1.00"Color="#FF009CFF"/>

</LinearGradientBrush>
</Application.Resources>
BackgroundWindowResource.
XAMLBackgroundStackPanel,
BackgroundWindowResource.
<StackPanelBackground="{StaticResourceBackgroundWindowResource}">
...
</StackPanel>
WPF(
).

,
.
..
,Hyperlink,:
<Hyperlink></Hyperlink>
HyperlinkNavigateUri.
.,
NavigateUri="Page2.xaml".
WPF,,
.,

TextBlock,.
:,,,,
.XAML.
<TextBlockMargin="25,30,5,5">
<HyperlinkNavigateUri="PageEmployee.xaml"></Hyperlink>
</TextBlock>
WPF.
<ButtonMargin="25,15"Width="60"HorizontalAlignment="Left"
Command="Close"></Button>
WPF.4.12.

.4.12.WPF

.
PageEmployee.
StackPanel.,
.
<Pagex:Class="WpfApplProject.PageEmployee"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markupcompatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"d:DesignHeight="300"d:DesignWidth="600"

Title="PageEmployee">

<StackPanelMargin="3"Background="{StaticResourceBackgroundWindowResource}">
</StackPanel>
PageEmployee,
,,.
.

WPF.,
,,.
Menu,Windows
,,
.MenuItem()Separator().
MenuItemHeader,.
MenuItem,.Separator
,.StackPanelPageEmployeeXAML
,.

,,,,.
,,.
<Menu>
<MenuItemHeader="">
<MenuItemHeader=""></MenuItem>
<Separator></Separator>
<MenuItemHeader=""></MenuItem>
<MenuItemHeader=""></MenuItem>
<MenuItemHeader=""></MenuItem>
<MenuItemHeader=""/>
<Separator></Separator>
<MenuItemHeader=""></MenuItem>
</MenuItem>
<MenuItemHeader=""></MenuItem>
</Menu>
PageEmployee.
(.4.13).

.4.13.PageEmployee
,
.,
,,,,,
.
.
Images,
VisualStudio(VS2010ImageLibrary).
(.
4.14).

.4.14.Images
XAMLPageEmployee.
NameToolTip
.
Margin.
ImageSource,
.
<ToolBarName="ToolBar1"Margin="3">
<ButtonName="Undo"ToolTip="/"
Margin="5,2,5,2">
<ImageSource="Images/Undo.jpg"/>
</Button>

...

</ToolBar>
VisualStudioPageEmployee,.4.15.


.4.15.PageEmployee
(Add)
PageEmployee,.4.16.
PageEmployee
.
:ListBox,ListView,TextBox,
TextBlock,ComboBox,DataGrid.

.4.16.PageEmployee
DataGrid
."".
DataGrid,
.DataGrid,.
:
DataGridTextColumn
DataGridCheckBoxColomn
DataGridComboBoxColomn,

DataGridHyperlinkColomnUri.
DataGrid.
AutoGenerateColumnsfalse.
(Columns),
DataGridTemplateColumn.
DataGrid..4.1
.

4.1.

AlternationIndex2,
BrushRowBackground
AlternatingRowBackground.

SelectionModeSelectionUnit.

StyleColumnHeaderStyle,
RowHeaderStyle,CellStyleRowStyle.
,

SelectedCells,
,SelectedItems,
.

CanUserAddRows,CanUserDeleteRows,
CanUserReorderColumns,CanUserResizeColumns,

CanUserResizeRowsCanUserSortColumns.

AutoGeneratingColumn.

FrozenColumnCount1
,
DisplayIndex0.

XML.

ItemsSourceDataGridXPath,
.
DataGrid.,XPath
,
.

XAMLPageEmployee.
<TextBlockMargin="5"></TextBlock>
<DataGridName="DataGridEmployee">
<DataGrid.Columns>
<DataGridTextColumnHeader=""/>

<DataGridComboBoxColumnHeader=""/>
<DataGridTemplateColumnHeader=""/>

...

</DataGrid.Columns>
</DataGrid>
,,,
DataGridTextColumn.
,,,
DataGridComboBoxColumn.
,DataGridTemplateColumn,.
PageEmployee,
.4.17.

.4.17.PageEmployeeDataGrid
PageEmployee,.4.18

.4.18.PageEmployeeDataGrid
PageEmployee
.

PageEmployee(,
,,,)
.WPF
.

.WPF
,
..
.
,,
MenuItemButton.,
.
,ICommand.
Execute,CanExecuteCanExecuteChanged.
WPF.
:
ApplicationCommands
NavigationCommands
EditingCommands
MediaCommands.
RoutedCommand,
ICommand.
,,
WPFApplicationCommands,
.
Commands
DataCommands.
publicclassDataCommands
{
publicstaticRoutedCommandDelete{getset}
publicstaticRoutedCommandEdit{getset}
staticDataCommands()
{
InputGestureCollectioninputs=newInputGestureCollection()
inputs.Add(newKeyGesture(Key.E,ModifierKeys.Control,"Ctrl+E"))
Edit=newRoutedCommand("Edit",typeof(DataCommands),inputs)
inputs=newInputGestureCollection()

inputs.Add(newKeyGesture(Key.D,ModifierKeys.Control,"Ctrl+D"))
Delete=newRoutedCommand("Delete",typeof(DataCommands),inputs)
}
}
DataCommandsDeleteEditRoutedCommand.
RoutedCommand,ICommand.
inputsInputGestureCollection.InputGestureCollection
InputGesture,KeyGesture
.
PageEmployeeXAML
,DataCommands.
command.
xmlns:command="clrnamespace:WpfApplProject.Commands"
PageEmployeeCommandBinding,
,
.
<Page.CommandBindings>
<CommandBindingCommand="Undo"
Executed="UndoCommandBinding_Executed"
CanExecute="UndoCommandBinding_CanExecute"/>

...

</Page.CommandBindings>
CommandBindingCommand,
ExecutedCanExecute.
:,,,,
.
.CanExecuteCanExecuteChanged,
.,
.,,
.
:
(1)
(2)
(3)
(4).
.4.19,,
.

.4.19.
(.
4.2).

4.2.

false

false

true

true

true

true

2
3

false
true

false
true

true
false

true
false

true
false

true
false

true

true

false

false

false

false

.4.2,12
34.(
12,34),
.
PageEmployeeisDirty
.
privateboolisDirty=true
(Executed),
.
isDirty.
.
privatevoidUndoCommandBinding_Executed(objectsender,
ExecutedRoutedEventArgse)
{
MessageBox.Show("")
isDirty=true
}
.

(CanExecute),
..4.2,
,.
privatevoidEditCommandBinding_CanExecute(objectsender,CanExecuteRoutedEventArgse)
{
e.CanExecute=isDirty
}
privatevoidSaveCommandBinding_CanExecute(objectsender,CanExecuteRoutedEventArgse)
{
e.CanExecute=!isDirty
}
XAMLCommand
.
(Menu)XAML.
<Menu>
<MenuItemHeader=""BorderThickness="3">
<MenuItemHeader=""Command="Undo"></MenuItem>

...

</Menu>
XAMLToolBar.
<ToolBarName="ToolBar1"Margin="3">
<ButtonName="Undo"Margin="5,2,5,2"Command="Undo"
ToolTip="/">
<ImageSource="Images/Undo.jpg">
</Image>
</Button>
...
</ToolBar>
.4.20
.4.21.

.4.20.

.4.21.
,,(.4.22).

.4.22.
,
.

WPF,,,,,,
,,,,,.
MainWindow,xmlns,partial,InitializeComponent,NavigationWindow,Frame,FrameworkElement,Page,
Hyperlink,NavigateUri,Menu,MenuItem,DataGrid,DataGridTextColomn,DataGridCheckBoxColomn,
DataGridComboBoxColomn,DataGridHyperlinkColomn,DataGridTemplateColumn,ICommand,Execute,
CanExecute,CanExecuteChanged,CommandBinding.

WPF,
,,,
,
.

1.ApplicationDevelopment//http://msdn.microsoft.com/ruru/library/ms754032.aspx.
2.//http://msdn.microsoft.com/ruru/library/ms745058.aspx.
3.//http://msdn.microsoft.com/ruru/library/ms753307.aspx.
4.[4],.82174,288362.
5.[6],.11711212
6.[8],.297351,565625.
7.[9],.10481070.

1.WPF?
2.InitializeComponent()?
3.Page?
4.ContentPage.
5.WPF?
6.?
7.?
8.DataGrid?
9.WPF.
10.WPF?
11.WPF?
!,Ctrl+Enter.
"",2016|www.intuit.ru