Mirza Adnan Hassan-DC130400143. Page No.
Chapter NO.24 Short Notes
1). Commands are a more robust and loosely coupled version of:
Events
2). WPF defines a number of
Built-in Commands
3). Any object can work as a command by:
Implementing icommand
4). icommand includes:
Execute
CanExecute
CanExecuteChanged
5). For cut, copy and paste we can define and implement three classes implementing
icommand
6).Pre-defined Built-in Commands:
Application Commands
Component Commands
Media Commands
Navigation commands
Editing Commands
7). All instances of RoutedUiCommand implement icommand and support bubbling
8). Custom Commands don’t get the treatment of CommandConverter.
9). You can add KeyBinding and MouseBinding yourself.
10). Example of KeyBinding:
This.InputBinding.Add(New KeyBinding(ApplicationCommands.Help, new
KesyGeasture(Key.F2)));
<Windows.InputBindings>
<KeyBinding Command = “Help” Key = “F2”>
<KeyBinding Command = “NotaCommand” Key = “F1”>
Mirza Adnan Hassan-DC130400143. Page No.2
</Windows.InputBindings>
This.InputBinding.Ass(New KeyBinding(ApplicationCommands.NotaCommand, new
KeyGesture(Key.F1)));
11). TextBox is an example of Control with builtin command binding that responds to
ctrl-z etc.
12). WPF Input Events make possible rich interactive content.
13). Application Commands:
Close Save
Copy SaveAll
New Stop
Open Undo
Cut Delete
Print Find
Properties Replace
Save SaveAs
Stop Undo
14). Component Commands:
MoveDown ScrollPageRight
MoveLeft ScrollPageUp
MoveRight SelectToHome
SelectToEnd MoveUp
ScrollByLine SelectToPageDown
ScrollPageDown SelectToPageUp
ScrollPageLeft
15).Media Commands:
ChannelDown ChannelUp
DecreaseVolume FastForward
IncreaseVolume MuteVolume
NextTrack Pause
Play PreviousTrack
Record Rewind
Select Stop
16). Navigation Commands:
BrowseBack BrowseForward
BrowseHome BrowseStop
Favorites FirstPage
GoToPage LastPage
Mirza Adnan Hassan-DC130400143. Page No.3
NextPage PreviousPage
Refresh Search
Zoom
17). Editing Commands:
AlignCenter AlignJustify
AlignLeft AlignRight
CorrectSpellingError DecreaseFontSize
DecreaseIndentation EnterLineBreak
EnterParagraphBreak IgnoreSpellingError
IncreaseFontSize IncreaseIndentation
MoveDownByLine MoveDownByPage
MoveDownByParagraph MoveLeftByCharacter
MoveLeftByWord MoveRightByCharacter
MoveRightByWord
Chapter NO.25 Short Notes
1).WPF Window is a:
win32 window
2). Any Number of child windows can be made by
instantiating a window derived class and calling show
3). Child windows gets closed or minimized:
on closing or minimizing of parent window
4). Window Events include:
Activated
Deactivated
5).Using Window.Show() a window appears and then disappears
6). StartupUri in xaml is
<Application x:Class = “PhotoGallery.App”
xmlns = http://schemas.microsoft.com.winfx/2006/xaml/presentation
xmlns: x = http://schemas.microsoft.com/winfx/2006/xaml
StartupUri = “MainWindow.xaml”/>
Mirza Adnan Hassan-DC130400143. Page No.4
7). main() is created dynamically
8). System.Environment.GetCommandLineArgs is used to get command line arguments
in WPF
9). Application Level Events are:
Startup
Exit
Activated
Deactivated
SessionEnding
10). Window.show() is used to instantiate (Read-only) window.
11). Properties Dictionary is a simple Dictionary used to share things among different
windows.
12). Application.Current() is used to take current window from any app.
13). Dispatcher.Run() is used to make multiple UI threads.
14). Single Instance App:
Bool mutexIsNew;
using (System.Threading.Mutex m = New System.Threading.Mutex(True, uniqueName,
out mutexIsNew))
{
if(mutexIsNew)
// This is the first instance. Run the application
else
// There is already an instance running
}
15). Dialogs are just child windows
16).There are two types of dialogs:
Modal
Modeless
17). Modeless Dialog are more like normal Windows.
18). Modal Dialog are such windows that are necessary to terminate explicitly in order to
interact with main window.
Mirza Adnan Hassan-DC130400143. Page No.5
19). In modeless Window we can work in parallel with main window just like using Tools
window in Photoshop.
20).Common Dialogs are actually provided by win32 and are part of Modal dialog.
21). Custom Dialogs are user-defined.
22). ShowDialog() returns us Null-able Boolean with options True/False/Null.
23). Apllication Deploy include:
ClickOnce
Windows Installer
24). EULA stand for End User License.
25). Benefits of Windows Installer:
showing custom setup UI like EULA
Control over where files are installed
Arbitrary code at install time
Register COM components and File Association
Install for All users
Installation From CD
26). Benefits of ClickOnce:
Built-in support for automatic updates and roll back to previous version
A web-like go-away experience
Start-menu or control panel program list
All files in isolated area
Clean Un-installation
Chapter NO.26 Short Notes
1) Wizard is a Dialog Box with multiple User-Interfaces.
2). Difference Between Page and Window:
Page in itself cannot Display. Window is an area containing page.
3). Child windows gets closed or minimized:
on closing or minimizing of parent window
4). Navigation Based apps are:
Windows Explorer
Mirza Adnan Hassan-DC130400143. Page No.6
Media Player
Photo Gallery
5). Host Windows are:
Navigation Window
Frame
6). Navigation Containers Provide:
Navigating
History Journal
Navigation Related events
7). Difference between Navigation Window and Frame:
Navigation window gives you a navigation Bar by default while Frame does not.
Navigation Window is more like a top-level window wherease Frame more like an HTML
frame or iFrame.
8). Page does everything that windows does except OnClosed and OnClosing.
9). Navigation can also happen between HTML files.
10). A page can interact with its Navigation Container by using NavigationService Class.
11). You can get an instance of NavigationService by calling the static
NavigationService.GetNavigationService method and passing an instance of the page.
12). this.NavigationService.Refresh() results in reload of current page.
13). Performing navigation in 3 main ways:
calling navigation method
Using Hyperlinks
Using the Journal
14). Properties of page:
WindowHeight
WindowWidth
WindowTitle
15). Example Of Navigate Method:
PhotoPage nextPage = new PhotoPage();
this.NavigationService.Navigate(nextPage);
Mirza Adnan Hassan-DC130400143. Page No.7
16). Navigate to a page via Uri
this.NavigateService.Navigate(new Uri(“photoPage.xaml”, uriKind.Relative));
17). Example of navigation using Hyperlink.
<textblock>
Click
<Hyperlink NavigateUri = “photoPage.xaml”>
Here
</Hyperlink>
to view the photo
</textblock>
18). Journal provides logic behind back and frwd.
19). Two internal stacks are:
Undo
Redo
20).Navigation Window always has a journal but frame may depending on its
JournalOwnership = OwnsJournal, UseParenJournal, Automatic
21). When frame has journal it has back/frwd buttons but can set NavigationUiVisibility
= Hidden
22). Navigation Events that raise when loading first page:
See in handouts
23). Navigation Events that raise when navigating between pages.
See handouts
23). NavigationIsstopped is an event called instead of LoadCompleted if an error occurs
or navigation is cancelled.
24). Html to html event firing is not allowed.
25). PageFunction has special mechanism for returning data.
Chapter NO.27 Short Notes
1). Browser based Applications are partial trust applications.
2). Partial Trust means with some restrictions.
Mirza Adnan Hassan-DC130400143. Page No.8
3). Basic benefit of Silverlight is that it is cross-platform. But WPF browser based
applications just run on windows.
4). In Web Based applications the journal of Application and Web Browser are
integrated.
5). GAC is a Global Assembly Cache
6). ClickOnce Applications are chached.
7). How to open file from local system:
String filecontents = null;
OpenFileDialog ofd = new openFileDialog();
if(ofd.ShowDialog()==true)
{
using(stream s = ofd.OpenFile())
using(StreamReader sr = new StreamReader())
{
filecontent = sr.ReadToEnd();
}
}
8). Data can be given to any web site using two method:
URL Parameter
Cookies
9). BrowserInteropHelper.Source to retrieve the complete URL.
10). Browse Cookies retrieved by Application.GetCookie method.
11). Two steps of making full-trusted Web Browser App.
Change:
<targetzone>Internet</targetzone>
to
<targetzone>Custom</targetzone>
Add:
<permissionset class = “System.Security.Permissionset” version = “1” ID = “Custom”
samesite = “site” Unrestricted = “true”/>
12). To publish a web based application use VS publishing wizard or mage tool in SDK
and copy files to webserver which must be configured to serve it.
Mirza Adnan Hassan-DC130400143. Page No.9
13). Users can install and run a web based application just by navigating to a URL.
14). Resources can be:
Binary
Logical
15). .Net has binary resources in WPF.
16). Binary resources can be:
Embedded(part of exe)
Stored at Known place
17). Localization:
Localization means that your application can target more than one target languages or
target Grammers.
18). In Order to localize resources its necessary to make them embedded resources.
Chapter NO.28 Short Notes
1) How to specify Default Culture of Application:
<project>
<propertygroup>
<uiculture>en-US</uiculture>
[assembly: NautralResourceLanguage(“en-US”,
UltimateResourceFallBackLocation.Satellite]
2). Logical Resources are arbitrary .net objects stored and named in an element
Resource Properties.
3). By using logical resources we can save change in one place and have different effects.
Like you can change brushes in one place and have different effects .
4). Logical Resources can further be categorized in “Static Resources” and “Dynamic
Resources”.
5). In Dynamic Resources we actually subscribe to the updates of the resource.
6). In static resource we just want its value once.
Mirza Adnan Hassan-DC130400143. Page No.10
7). Static Resource markup extension walks the logical tree or even application level or
system Resources.
8). Example of Static Resource:
<windows xmlns:http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns: x = http://schemas.microsoft.com/winfx/2006/xaml>
<window.Resources>
<Image x: key = “Zoom” Height = “21” Source = “Zoom.gif”/>
</window.Resources>
<StackPanel>
<StaticResource ResourceKey = “zoom”/>
</StackPanel>
</window>
9). Static Resources do not support forward references.
10). Static Resources do not support Sharing.
11). Procedural Code/Static Resource:
window.Resources.add(“BackgroundBrush”, new SolidColorBrush(Colors.Yellow));
Window.Resources.Add(“BorderBrush”, new SolidColorBrush(Colors.Red));
Button button = new Button();
StackPanel.Children.Add(button);
Button.Background = (Brush)button.FindResource(“BackgroundBrush”);
Button.BorderBrush = (Brush)button.FindResource(“BorderBrush);
12). Procedural Code/Dynamic Resource
Button button = new Button();
Button.SetResourceReference(Button.BackgroundProperty, “BackgroundBrush”);
Button.SetResourceReference(Button.BorderBrushProperty, “BorderBrush”);
Button button = new Button();
Button.Background = (Brush)window.Resources[“BackgroundBrush”];
Button.BorderBrush = (Brush)window.Resources[“BorderBrush ”];
13). The key benefit of logical resources is that Use and definition becomes seprate.
14). System Resources are such resources which are shared by al application For
Example: System Color, System font, System Parameters.
Chapter NO.29 Short Notes
Mirza Adnan Hassan-DC130400143. Page No.11
1). Data Binding allows to declaratively bind two different properties in xaml.
2). Binding Object has one source and target Object.
3). Binding binds two propertiews together and keeps a communication channel open.
4). Example code of binding:
public mainWindow()
{
InitializeComponent();
Binding binding = new Binding();
Binding.Source = TreeView;
Binding.Path = new PropertyPath(“SelectedItem.Header”);
CurrentFolder.SetBinding(TextBlock.TextProperty, binding);
}
5). Property.Pah can also use
BindingOperation.SetBinding
BindingOperation.ClearBinding
BindingOperation.ClearAllBindings
6). The DisplayMemberPath property can be used to improve display:
<listbox x:Name= “pictureix” DiaplayMemberPath = “Name”
ItemSource = “{Binding source ={StaticSource photos}}”>
</listbox>
7). Synchronization means binding multiple targets with single source.
8). Example Code Of Synchronization:
<listbox IsSynchronizedWithCurrentItem = “True” DisplayMemberPath = “Name”
ItemSource = “{Binding source={StaticSource photos}}”
</listbox>
<listbox IsSynchronizedWithCurrentItem = “True” DisplayMemberPath = “DateTime”
ItemSource = “{Binding source={StaticSource photos}}”
</listbox>
<listbox IsSynchronizedWithCurrentItem = “True” DisplayMemberPath = “Size”
ItemSource = “{Binding source={StaticSource photos}}”
</listbox>
9). Data Context is a method of defining Default Data Source.
10). example Code of Data Context:
<stackpanel DataContext = “{StaticSource photos}”>
Mirza Adnan Hassan-DC130400143. Page No.12
<label x:Name =”numitemslabel”
content = “{Binding Path=Count}”/>
<listbox s:Name = “picturebox” DisplayMemberPath = “Name”
Itemsource = “{Binding}”>
</listbox>
</stackpanel>
11). Three Ways of Control Rendering are:
String formatting
Data Template
Value Converter
12). String Formatting can be used even without Data Binding
13). With Data Template User Interface are auto-applied to arbitrary .net object when it
is rendered.
14). Example Code of Data Template:
<listbox x:Name = “picturebox”
ItemSource = “{Binding Source={StaticResource photos}}”>
<listbox.ItemTemplate>
<DataTemplate>
<Image Source = “placeholder.jpg” Height = “35”/>
</DataTemplate>
</listbix.ItemTemplate>
</listbox>
15). With Data Template there is an implicit DataContext.
16). Value Converter is a custom Logic that morphs Source value into Target Type.
Chapter NO.30 Short Notes
1). View Supports:
Sorting
Grouping
Filtering
Navigation
2). Example of sorting on one field:
SortDescription sort = new SortDescription(“Name”, ListSortDirection.Ascending);
Mirza Adnan Hassan-DC130400143. Page No.13
3). Example of sorting on two Different Fields:
View.SortDescription.Add(new SortDescription(“DateTime”, ListSortDirection.Descending);
View.SortDescription.Add(new SortDescription(“Name”, ListSortDescription.Ascending);
4). Method of Getting Default View:
IcollectionView view = CollectionViewSource.getDefaultSource(this.FindSource(“photos”));
5). Example of Grouping:
IcollectionView view = CollectionViewSource.getDeafultView(this.FindSource(“photos”));
View.GroupDescriptions.Add(new PropertyGroupDescription(“DateTime”));
6). Example Of Filtering:
IcollectionView view =
CollectionViewSource.getDefaultView(this.FindResource(“photos”));
View.Filter = delegate(object o){
Return((o As photo).DateTime-DateTime.Now).Days<=7;
};
7). Example of Navigation in View:
void previous_Click(Object sender, Routedevent e)
{
IcollectionView view =
CollectionViewSource.getDefaultView(this.FindResource(“photos”));
view.MoveCurrentToPrevious();
if(view.IsCurrentBeforeFirst)
view.MoveCurrentToLast();
}
void next_Click(Object sender, Routedevent e)
{
IcollectionView view =
CollectionViewSource.getDefaultView(this.FindResource(“photos”));
view.MoveCurrentToNext();
if(view.IsCurrentAfterLast)
view.MoveCurrentToFirst();
}
8). Binding to the whole object:
“{Binding Path = /}”
9). Binding to the DateTime Property
“{Binding path=/DateTime}”
10). Binding on a current item of a different Data Source:
Mirza Adnan Hassan-DC130400143. Page No.14
“{Binding Path=Photo/}”
11). Binding to the DateTime Property of different data source:
“{Binding Path=Photos/DateTime}”
12). Sorting is always applied before Grouping
13). Navigation means managing the current item in view.
14). If you have multiple target elements connected to the same Custom View then their
IsSynchronizedWithCurrentItem = “True” by default and it is “false” in Default View.
15). Data Providers are kind of classes which made it simple for us to access certain kind
of data.
16). There are two types of Data Providers:
xaml Data Providers
Object Data Providers
Chapter NO.31 Short Notes
1). Object Data Provider provides us some facility which are useful for binding to objects
which are not designed for binding.
2). Asynchronous Data Binding means that the property that you want to access should
be done in background.
3). xmlDataProvider and objectDataProvider have an IsAsynchronous property. Which is
false by default on ObjectDataProvider and true by default for xmlData Provider.
4). Example of Object Data Provider:
<window.Resources>
<local:Photos x:key = “photos”/>
<ObjectDataProvider x:key = “dataprovider”
ObjectInstance = “{StaticSource photos}”/>
</window.Resources>
5). Binding to a method is useful for classes that are not designed for Data Binding.
6). Convert Method is used when bringing data from Source to Target
Mirza Adnan Hassan-DC130400143. Page No.15
7). Convert Back is used when bringing data from target to source.
8). Binding Modes:
One-Way
Two-Way
OneWayToSource
OneTime
9). Example of Method Data Binding:
<ObjectDataProvider.ConstructorParameter>
<Sys:Int32>23</sys:Int32>
</ObjectDataProvider.ConstructorParameters>
</ObjectDataProvider>
<ObjectDataProvider x:key=”DataProvider”
ObjectType=”{x:Type local:photos}”
MethodName = “getFolderName”/>
10). One-Way Binding means the target is updated whenever the source changes.
11). Two-Way Binding means change to either the target or source updates the other
12). OneWayToSource is the opposite of One-Way binding. the source is changed
whenever the target changes.
13). One-Time binding is like one-way except changes to the source are not reflected at
the target. The target retains a snapshot of the source at the time the Binding is
initiated.
14). when Do you want the two way source to be updated:
PropertChanged
LostFocus
Explicit
15). Validation Rules are just like simple classes that are used to ensure the proper
working of the application.
16). Binding has ValidationRules Property that can be set to one or more validation rules
17). ExceptionValidationRule says that you can update a source if updating a source does
not cast an exception.
Mirza Adnan Hassan-DC130400143. Page No.16
Chapter NO.32 Short Notes
1). Concurrency means doing two things at the same time.
2). Purposes of Concurrency are:
Responsive User Interface
Simultaneous Requests
Parallel Programming
3). Time slicing means giving time to a thread then we slice and run another thread then
come back and so on.
4). Creating a Simple thread in C#:
Class ThreadTest
{
Static void main()
{
Thread t = new Thread(WriteY);
t.Start();
for(int i = 0; i<1000; i++) Console.Write(“x”);
}
Static void WriteY()
{
for(int I = 0; i<1000; i++) Console.Write(“y”);
}
}
5). A Thread isAlive = true once starts and until end.
6). Thread.CurrentThread is currently executing thread.
7). When you call t.join() it means you want to wait for t to finish.
8). Sleep() means a thread wants to give away the CPU.
9). Local Variables are kept on stack.
Mirza Adnan Hassan-DC130400143. Page No.17
10). Locks are a way to ensure that if you are in area of a code then no other thread will
be allowed to enter that area of thread. And are used when threads are sharing shared
data.
11). Example of Lock:
Class ThreadSafe
{
Static Bool _done;
Static ReadOnly Object _locker = new object();
Static void main()
{
new Thread(Go).Start();
Go();
}
Static void Go()
{
Lock(_locker)
{
if(!_done){Console.WriteLine(“Done”); _done = true;}
}
}
}
12). Example of passing Data to Threads:
Static void main()
{
Thread t = new Thread(()=> Print(“Hello From t!”));
t.Start();
}
Static void Print(String message)
{Console.WriteLine(message);}
13). Lambda ()=> is used to pass data to threads.
14). for(int i = 0; i<10; i++)
new Thread(()=>Console.Write(i)).Start(); will result in some typical output like
0223557799 just because of sharing a common variable and thread concurrency
15). above code can be rectified as follows:
for(int i = 0; i<10; i++)
{
int temp = i;
new Thread(()=> Console.Write(temp)).Start(); }