What is a resource (in terms on .net)?

A resource is a noncode piece of an application or compnent like bitmaps, fonts, audio / video files, string tables.

WPF supports 2 different types of resources –

Binary Resource

Binary resources are what the rest of the .NET framework conciders as resources and in WPF apps they are traditional items like bitmaps. You might also be surprised to know that XAML is also stored as a binary resource behiend the scenes. Binary resources are packaged in three different ways:

  • Embedded inside an assembly
  • Loose files that are known to the application at complie time
  • Loose files that are not known to the applcation to the compile time.

Now we can also categorize binary resources into Localizable (change depending on the current culture) and Non Localizable (do not change based on culture).

Lets see how can we define access and localize birary resources.

Defining a Binary Resource

As shown in the image below, you select the Build Action property and set it to either Resource or Content.

Define Resource Prop in VS

Define Resource Prop in VS

Select Build Action as Resource when you want to include your resource in the assembly and Select Build Action as Content when you want your resourcfe to be a loose file and only the existence and relative location of the file sould be included in the assembly.

Now if you would have noticed the above image carefully (you can have a look again if you want) then you will see there is another value by the name of Embedded Resource (this also embeds the resource into the assembly just like Resource). The use of this value is not recomended in WPF as this property belongs to old .net and was ment to be used with Windows Forms. Also if you select your resource to an Embedded Resource then you will not be able to access it in XAML (unless you write some custom code for the same).

[highlight]Note – As a rule of thumb you should embed the resource (with the Resource build action) only when the resouce is localizable or you specificly need single binary or resource within binary else you should prefer Content build action.[/highlight]

Accessing a Binary Resource

In WPF you can access a binary resource from code ox XAML through a URI (uniform resource identifier). And a types converter will help us to specify URIs in XAML as simple strings. The code below demonstrates how simple we can access resources whose build action property has been set to either Resource or Content but they have been included in the project

<Image Height=21Source=slideshow.gif/>

Note – A compiled XAML cannot reference a binary resource in the current  directory via its simple filename unless it has been added to the project. For  accessing files that are not added into the project either give the full path of the resource or access resource using Site of Origin url.

<Image Height=21Source=C:\\Users\\Adam\\Documents\\slideshow.gif/>

<Image Height=21Source=pack://siteOfOrigin:,,,/slideshow.gif/>

Below here is the list present for refernce of how to acces which binary resource.

Resource Type URI Mapping

Resource Type URI Mapping

 

Accessing Resources from Procedural Code

If you want to access resources from your C# or vb.net code the XAML specific shortcuts will not work but the URIO should be fully qualified. Below is an example for the same:

Image image = new Image();

image.Source = new BitmapImage(new Uri(“pack://application:,,,/logo.jpg”));

So the above lines of code will instantiate a System.Windows.Media.Imaging.BitmapImage object which ultimately derives from the abstract ImageSource type and this will work with popular image formats such as JPEG, PNG, GIF, BMP. The use of pack://application:,,,/ works only with resources belonging to the current project marked as Resource or Content. To reference relative loose files with no relation to the project, the easiest approach is to use a siteOfOrigin-based URI.

Localizing a Binary Resource

If your application contains some binary resources that are specific to certain cultures then we can partition them into satellite assemblies (one for each culture) and get them loaded automatically when appropriate. And if you are having binary resources for localization then there is a very good chance that you have string in your UI for localization. Here we could make use of LocBaml (sample tool in windows SDK) which will make it very easy to manage localization of strings and other items without removing them from XAML and manually apply a level of indirection. Lets have a look as to how can we use LocBaml and Satellite Assemblies. Remember this is just an overview on how you can proceed with it. To specify a default culture for resources and automatically build an appropriate satellite assembly, you must add a UICulture element to the project file. Visual Studio doesn’t have a means to set this within its environment, so you can open the project file in your favorite text editor instead. The UICulture element should be added under any or all  PropertyGroup elements corresponding to the build configurations you want to affect (Debug, Release, and so on), or to a property group unrelated to build configuration so it automatically applies to all of them. This setting should look as follows for a default culture of American English:

<Project …>

<PropertyGroup>

<UICulture>en-US</UICulture>

……

 

If you rebuild your project with this setting in place, you’ll find an en-US folder alongside your assembly, containing the satellite assembly named  assemblyName.resources.dll. You should also mark your assembly with the assembly-level NeutralResourcesLanguage custom attribute with a value matching your default UICulture setting, as follows:

[assembly: NeutralResourcesLanguage(“en-US”, UltimateResourceFallbackLocation.Satellite)]

The next step is to apply a Uid directive from the XAML language namespace (x:Uid) to every object element that needs to be localized. The value of each directive should be a unique identifier. This would be extremely tedious to do by hand, but it fortunately can be done automatically by invoking MSBuild from a command prompt, as follows:

msbuild/t:updateuid ProjectName.csproj

Running this gives every object element in every XAML file in the project an x:Uid directive with a unique value. You can add this MSBuild task inside your project before the Build task, although this might produce too much noise if you rebuild often.

After compiling a project that has been enhanced with Uids, you can run the LocBaml tool from the Windows SDK on a .resources file generated by the build process (found in the obj\debug directory), as follows:

LocBaml /parseProjectName.g.en-US.resources /out:en-US.csv

This generates a simple .csv text file containing all the property values you should need to localize. You can edit the contents of this file so it correctly corresponds to a new culture. (There’s no magic in this part of localization!) If you save the file, you can then use LocBaml in the reverse direction to generate a new satellite assembly from the .csv file!

For example, if you changed the contents of the .csv file to match the French Canadian culture, you could save the file as fr-CA.csv and then run LocBaml as follows:

LocBaml /generate ProjectName.resources.dll /trans:fr-CA.csv /cul:fr-CA

This new satellite assembly needs to be copied to a folder alongside the main assembly with a name that matches the culture (fr-CA in this case).

To test a different culture, you can set System.Threading.Thread.CurrentThread.CurrentUICulture (and System.Threading.Thread.CurrentThread.CurrentCulture) to an instance of the desired CultureInfo.

Logical Resource

As you might have gussed logical resources are the ones which are arbitary .NET objects stored in an element’s resources property (meant to be shared by multiple child elements). The base clases of both FrameworkElement and FrameworkContentElement have a Resource Property. The examples of logical resources are
styles,data provides, etc.

Lets see an XAML code for a logical resource which is Brush. The following example shows a simple windows with a row of buttons along the bottom which can be used in a photo gallery user interface. This example shows how to apply custom brush to each Button’s Background and BorderBrush.

<Window xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation Title =”Simple Window” Background=”Yellow”>

    <DockPanel>

        <StackPanel DockPanel.Dock=”Bottom” Orientation=”Horizontal” HorizontalAlignment=”Center”>

            <Button Background=”Yellow” BorderBrush=”Red” Margin=”5″>

                <Image Height=”21″ Source=”zoom.gif”/>

            </Button>

            <Button Background=”Yellow” BorderBrush=”Red” Margin=”5″>

                <Image Height=”21″ Source=”defaultThumbnailSize.gif”/>

            </Button>

            <Button Background=”Yellow” BorderBrush=”Red” Margin=”5″>

                <Image Height=”21″ Source=”previous.gif”/>

            </Button>

            <Button Background=”Yellow” BorderBrush=”Red” Margin=”5″>

                <Image Height=”21″ Source=”slideshow.gif”/>

            </Button>

            <Button Background=”Yellow” BorderBrush=”Red” Margin=”5″>

                <Image Height=”21″ Source=”next.gif”/>

            </Button>

            <Button Background=”Yellow” BorderBrush=”Red” Margin=”5″>

                <Image Height=”21″ Source=”counterclockwise.gif”/>

            </Button>

            <Button Background=”Yellow” BorderBrush=”Red” Margin=”5″>

                <Image Height=”21″ Source=”clockwise.gif”/>

            </Button>

            <Button Background=”Yellow” BorderBrush=”Red” Margin=”5″>

                <Image Height=”21″ Source=”delete.gif”/>

            </Button>

        </StackPanel>

        <ListBox/>

    </DockPanel>

</Window>

Applying Custom Color Brushes Without Using Logical Resources

Applying Custom Color Brushes Without Using Logical Resources

Now lets implement Logical Resources

<Window xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=”http://schemas.microsoft.com/winfx/2006/xamlTitle=”Simple Window”>

<Window.Resources>

<LinearGradientBrush x:Key=”backgroundBrush” StartPoint=”0,0″ EndPoint=”1,1″>

<GradientStop Color=”Blue” Offset=”0″/>

<GradientStop Color=”White” Offset=”0.5″/>

<GradientStop Color=”Red” Offset=”1″/>

</LinearGradientBrush>

<SolidColorBrush x:Key=”borderBrush”>Red</SolidColorBrush>

</Window.Resources>

<Window.Background>

<StaticResource ResourceKey=”backgroundBrush”/>

</Window.Background>

<DockPanel>

<StackPanel DockPanel.Dock=”Bottom” Orientation=”Horizontal” HorizontalAlignment =”Center”>

<Button Background=”{StaticResource backgroundBrush}” BorderBrush=”{StaticResource borderBrush}” Margin=”5″>

<Image Height=”21″ Source=”zoom.gif”/>

</Button>

<Button Background=”{StaticResource backgroundBrush}” BorderBrush=”{StaticResource borderBrush}” Margin=”5″>

<Image Height=”21″ Source=”defaultThumbnailSize.gif”/>

</Button>

<Button Background=”{StaticResource backgroundBrush}” BorderBrush=”{StaticResource borderBrush}” Margin=”5″>

<Image Height=”21″ Source=”previous.gif”/>

</Button>

<Button Background=”{StaticResource backgroundBrush}” BorderBrush=”{StaticResource borderBrush}” Margin=”5″>

<Image Height=”21″ Source=”slideshow.gif”/>

</Button>

<Button Background=”{StaticResource backgroundBrush}” BorderBrush=”{StaticResource borderBrush}” Margin=”5″>

<Image Height=”21″ Source=”next.gif”/>

</Button>

<Button Background=”{StaticResource backgroundBrush}” BorderBrush=”{StaticResource borderBrush}” Margin=”5″>

<Image Height=”21″ Source=”counterclockwise.gif”/>

</Button>

<Button Background=”{StaticResource backgroundBrush}” BorderBrush =”{StaticResource borderBrush}” Margin=”5″>

<Image Height=”21″ Source=”clockwise.gif”/>

</Button>

<Button Background=”{StaticResource backgroundBrush}” BorderBrush =”{StaticResource borderBrush}” Margin=”5″>

<Image Height=”21″ Source=”delete.gif”/>

</Button>

</StackPanel>

<ListBox/>

</DockPanel>

</Window>

 

Consolidating Color Brushes with Logical Resources

Consolidating Color Brushes with Logical Resources

 

The list of useful run command is as below :

Run Commands Listed below
In Alphabetical Order
Program
Run Command
Accessibility Controls access.cpl
Accessibility Wizard accwiz
Add Hardware Wizard hdwwiz.cpl
Add/Remove Programs appwiz.cpl
Administrative Tools control admintools
Adobe Acrobat ( if installed
)
acrobat
Adobe Distiller ( if
installed )
acrodist
Adobe ImageReady ( if
installed )
imageready
Adobe Photoshop ( if
installed )
photoshop
Automatic Updates wuaucpl.cpl
Basic Media Player mplay32
Bluetooth Transfer Wizard fsquirt
Calculator calc
Ccleaner ( if installed ) ccleaner
C: Drive c:
Certificate Manager cdrtmgr.msc
Character Map charmap
Check Disk Utility chkdsk
Clipboard Viewer clipbrd
Command Prompt cmd
Command Prompt command
Component Services dcomcnfg
Computer Management compmgmt.msc
Compare Files comp
Control Panel control
Create a shared folder Wizard shrpubw
Date and Time Properties timedate.cpl
DDE Shares ddeshare
Device Manager devmgmt.msc
Direct X Control Panel ( if
installed )
directx.cpl
Direct X Troubleshooter dxdiag
Disk Cleanup Utility cleanmgr
Disk Defragment dfrg.msc
Disk Partition Manager diskmgmt.msc
Display Properties control desktop
Display Properties desk.cpl
Display Properties
(w/Appearance Tab Preselected )
control color
Dr. Watson System
Troubleshooting Utility
drwtsn32
Driver Verifier Utility verifier
Ethereal ( if installed ) ethereal
Event Viewer eventvwr.msc
Files and Settings Transfer
Tool
migwiz
File Signature Verification
Tool
sigverif
Findfast findfast.cpl
Firefox firefox
Folders Properties control folders
Fonts fonts
Fonts Folder fonts
Free Cell Card Game freecell
Game Controllers joy.cpl
Group Policy Editor ( xp pro
)
gpedit.msc
Hearts Card Game mshearts
Help and Support helpctr
Hyperterminal hypertrm
Hotline Client hotlineclient
Iexpress Wizard iexpress
Indexing Service ciadv.msc
Internet Connection Wizard icwonn1
Internet Properties inetcpl.cpl
Internet Setup Wizard inetwiz
IP Configuration (Display Connection Configuration) ipconfig /all
IP Configuration (Display DNS
Cache Contents)
ipconfig /displaydns
IP Configuration (Delete DNS
Cache Contents)
ipconfig /flushdns
IP Configuration (Release All
Connections)
ipconfig /release
IP Configuration (Renew All
Connections)
ipconfig /renew
IP Configuration (Refreshes DHCP & Re-Registers DNS) ipconfig /registerdns
IP Configuration (Display
DHCP Class ID)
ipconfig /showclassid
IP Configuration (Modifies
DHCP Class ID)
ipconfig /setclassid
Java Control Panel ( if
installed )
jpicpl32.cpl
Java Control Panel ( if
installed )
javaws
Keyboard Properties control keyboard
Local Security Settings secpol.msc
Local Users and Groups lusrmgr.msc
Logs You Out of Windows logoff
Malicious Software Removal
Tool
mrt
Microsoft Access ( if
installed )
access.cpl
Microsoft Chat winchat
Microsoft Excel ( if
installed )
excel
Microsoft Diskpart diskpart
Microsoft Frontpage ( if
installed )
frontpg
Microsoft Movie Maker moviemk
Microsoft Management Console mmc
Microsoft Narrator narrator
Microsoft Paint mspaint
Microsoft Powerpoint powerpnt
Microsoft Word ( if installed
)
winword
Microsoft Syncronization Tool mobsync
Minesweeper Game winmine
Mouse Properties control mouse
Mouse Properties main.cpl
MS-Dos Editor edit
MS-Dos FTP ftp
Nero ( if installed ) nero
Netmeeting conf
Network Connections control netconnections
Network Connections ncpa.cpl
Network Setup Wizard netsetup.cpl
Notepad notepad
Nview Desktop Manager ( if
installed )
nvtuicpl.cpl
Object Packager packager
ODBC Data Source
Administrator
odbccp32
ODBC Data Source
Administrator
odbccp32.cpl
On Screen Keyboard osk
Opens AC3 Filter ( if
installed )
ac3filter.cpl
Outlook Express msimn
Paint pbrush
Password Properties password.cpl
Performance Monitor perfmon.msc
Performance Monitor perfmon
Phone and Modem Options telephon.cpl
Phone Dialer dialer
Pinball Game pinball
Power Configuration powercfg.cpl
Printers and Faxes control printers
Printers Folder printers
Private Characters Editor eudcedit
Quicktime ( if installed ) quicktime.cpl
Quicktime Player ( if
installed )
quicktimeplayer
Real Player ( if installed ) realplay
Regional Settings intl.cpl
Registry Editor regedit
Registry Editor regedit32
Remote Access Phonebook rasphone
Remote Desktop mstsc
Removable Storage ntmsmgr.msc
Removable Storage Operator
Requests
ntmsoprq.msc
Resultant Set of Policy ( xp
pro )
rsop.msc
Scanners and Cameras sticpl.cpl
Scheduled Tasks control schedtasks
Security Center wscui.cpl
Services services.msc
Shared Folders fsmgmt.msc
Sharing Session rtcshare
Shuts Down Windows shutdown
Sounds Recorder sndrec32
Sounds and Audio mmsys.cpl
Spider Solitare Card Game spider
SQL Client Configuration clicongf
System Configuration Editor sysedit
System Configuration Utility msconfig
System File Checker Utility (
Scan Immediately )
sfc /scannow
System File Checker Utility (
Scan Once At Next Boot )
sfc /scanonce
System File Checker Utility (
Scan On Every Boot )
sfc /scanboot
System File Checker Utility (
Return to Default Settings)
sfc /revert
System File Checker Utility (
Purge File Cache )
sfc /purgecache
System File Checker Utility (
Set Cache Size to Size x )
sfc /cachesize=x
System Information msinfo32
System Properties sysdm.cpl
Task Manager taskmgr
TCP Tester tcptest
Telnet Client telnet
Tweak UI ( if installed ) tweakui
User Account Management nusrmgr.cpl
Utility Manager utilman
Volume Serial Number for C: label
Volume Control sndvol32
Windows Address Book wab
Windows Address Book Import
Utility
wabmig
Windows Backup Utility ( if
installed )
ntbackup
Windows Explorer explorer
Windows Firewall firewall.cpl
Windows Installer Details msiexec
Windows Magnifier magnify
Windows Management
Infrastructure
wmimgmt.msc
Windows Media Player wmplayer
Windows Messenger msnsgs
Windows Picture Import Wizard
(Need camera connected)
wiaacmgr
Windows System Security Tool syskey
Windows Script host settings wscript
Widnows Update Launches wupdmgr
Windows Version ( shows your
windows version )
winver
Windows XP Tour Wizard tourstart
Wordpad write
Zoom Utility igfxzoom

Guys please let me know if you liked the post………

In the words of Jensen Harris (director of the Windows Experience) “Every screen needs to be touch. A Monitor without touch feels dead.” So it means that Windows 8 is designed for touchscreens (tablets, All In One PCs and convertible laptops). But today i am just going to discuss how the new OS might transform the Windows Tablet Experience.

  • Metro UI and Apps – The Metro UI is obvious which Microsoft has preoccupied with tablets. The start screen comprises of groups of interactive tiles which is borrowed from Windows Phone 7 and Windows Media Center. The start screen scrolls horizontally very smoothly even on low powered ARM tablets. Now the tiles that you see here are not merely icons but are live widgets which deliver vital information without having to delve into the app itself. This means that the new app will scroll through the latest headlines, the flicker application will display thumbnail photo slideshow, live stocks, live whether, calander events, etc. The apps icons can be resized or repositioned according to application. If you are developer then you should know that Metro apps can be coded in C / C++ / C# but Microsoft appears to be nudging developers to work in HTML /CSS / Javascript bcoz the apps written in standard web languages will not need recompilation for ARM based devices. Now you might be exited to know that Metro apps are full screen with no taskbar and no close or minimize button. This means that if you want to kill the app you need to go to the task manager to kill the app. Also the apps are suspend by the OS when they are inactive. Now you can switch between the open apps by flicking your finger from the left hand side of the screen, just like turning the pages of a book. If the native resolution of your screen is 1366 X 768 or higher then you can run metro apps side by side where one app will be covering 75% of the screen and the other app will occupy a sliver on the left or right side.
windows-8-metro-apps

windows-8-metro-apps

windows-8-metro-apps

windows-8-metro-apps

windows-8-metro-apps

windows-8-metro-apps

  • The Windows Store – Metro apps will be downloadable exclusively from the Windows Store which is Microsoft’s response to Apple App Store and Android Market. Its quite obvious that microsoft will offer both free and paid apps although no confirmation regarding the same has been made from the side of Microsoft. Also leaked documents suggest that MS plan to take the same 30% cut on apps sales that Apple and Google do. Unique store design will allow developers to offer free trials that will expire and wiped from the devices after a set number of days. MS also plans to list additional apps in Windows store alongside the new metro apps which will redirect the users to the vendors sites.
win8appstore

win8appstore

  • Sharing and Syncing Apps – Metro apps will be synchronised all your windows 8 devices using the Windows Live account that’s linked to your user ID. This means that Metro apps are sold on user user basis rather per device but the nuber of devices will be limited. Also the synchronization will not only sync the app but also the data so that for example you can play the game on your tablet where you left it on your PC.
sync-pc

sync-pc

  • Text Input – The software keyboard is good and comes with couple of smart innovations like auto complete. The on screen keyboard can be split into 2 allowing the users of larger tablets to tap away with their thumbs on either side of the screen. For the stylus users, handwriting recognition is also an option.
windows-8-thumby-keyboard

windows-8-thumby-keyboard

  • Windows On ARM – The words of Windows Shief Steven Sinofsky “all apps for ARM are going to come through the store which meand they will be metro apps. ” suggest that Windows on ARM  could be pure tablet play designed to compete with iPad and android devices while intel based processors will be used for laptops, desktops and hybrids.
Microsoft-ARM-Powered-Windows-8-Tablet

Microsoft-ARM-Powered-Windows-8-Tablet

So guys, hope you enjoyed the article….Do post your comments and feedback…

Let me tell you some facts that you should know if you like computers….Not sure if all of them would come like a surprise to you but i guarantee that some of them will…..

So, here it goes. Ten myths and there truths.

  1. The internet was a military network designed to survive a nuclear attack – The precursor to the internet (APRANET) was funded by a branch of the US defence department. Howerver, its purpose was communication between universities and not war.
  2. Al Gore invented the internet – US Congressman, Al Gore promoted the concept of “comms” as something that could be good for both ecommerce and education in the 1970s.
  3. Al Gore said he invented the internet  – What actually Al Gore said was – “During my service in the United States Congress, i took the initiative in creating the internet”
  4. Packet Switching was invented by US – Actually an Englishmen called Donald Davies who was working at the National Physics Laboratory was also developing a packet switched network concept in the year 1965
  5. The first ever email said “QWERTYUIOP” – The first email was sent between teo PDP-10 computers in 1971 by BBN network engineer Ray Tomlinson. It comprised the equally boring “Testing 1-2-3”
  6. Ray Tomlinson sent first email – The MIT (Massachusetts Institute of Technology ) launched the mailbox system in 1965. It let users drop messages in the directories of the users of the same mainframe computer.
  7. Google Started Internet Search – The internet search tool was created way back in 1990 by compterscience students at McGrill university in Montreal.
  8. Netscape Navigator was the first web browser – The text – only linux browser was first off the mark in 1992, followed by NCSA Mosaic in 1993 and finally netscape navigator in 1994.
  9. The 404 error message is after a vacant room at CERN – Actually you will be surprised to know that there is no room number 404 at CERN labs in Switzerland. The 4xx class of error messages relates to problems where the client is thought to have gone wrong and the reminder is just a serial number.
  10. Social Networking is new – One of the first Social Netwroking site was The Well, a virtual community that started in 1985.

Do let me know if you liked my post. Also if you have something to share just add it here…..