Powered by Blogger.
🌏World roaming Software Technology Evangelist. Proud Indian, Bought up from Coimbatore, Tamilnadu, INDIA. Pointing towards share of Knowledge. 😎
  • Programming ▼
    • DotNet
      • C# Coding Standards
    • Cloud
    • Microsoft 365/ SharePoint
    • SQL
    • Angular / ReactJS / NodeJS
    • Salesforce
    • Magento
    • Python
    • Mobile App Development
    • Database
    • DevOps
    • Automation Testing
    • User Experience
  • Learning ▼
    • Roadmap
    • Trainings
    • E-Books
    • Quick References
    • Certifications
    • Self Improvement
    • Productivity
    • TED Talks
    • Kids Programming
  • Software Engineering ▼
    • Agile
    • Software Design
    • Architecture Samples
    • Best Practises
    • Technologies and Tools
    • Open Sources
    • Free Softwares
  • Leadership ▼
    • Program Management
    • Product Management
    • Project Management
    • People Management
  • Job Search ▼
    • Interview Tips
    • Career Handbook
    • Resume Templates
    • Sample Profiles
    • Cover Letter Samples
    • HR Interview Questions
    • Job Websites List
    • Coding Site Links
    • TedEx Talks
    • International Jobs
  • Emerging Topics ▼
    • Innovation
    • Machine Learning
    • Artificial Intelligence
    • Generative AI
    • AI Tools
    • Big Data
    • Data Science
    • Data Analytics & Visualization
    • Cyber Security
    • Microsoft Azure
    • Amazon Web Services
    • Cryptography
    • ChatBots
    • Internet of Things (IoT)
    • Mixed Reality /AR/VR
  • Misc. ▼
    • Travel
    • Photography
    • Health Tips
    • Medical Tips
    • Home Designs
    • Gardening
  • Favourite Links ▼
    • Saran Kitchen Hut
    • World of Akshu
    • Saran & Akshu - Other Links

 

Referred URL

http://www.kunal-chowdhury.com/2011/05/formatting-text-in-silverlight-xaml.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+kunal-chowdhury%2FSilverlight+%28Kunal%27s+Blog+-+Silverlight%29&utm_content=Google+Reader

Read to know more about it and make your life more comfortable designing your Silverlight application.

If you didn't read my previous two tips, you can find them here:

  • Tips: Formatting Silverlight TextBlock Control
  • Tips: Concatenating strings in Silverlight XAML using StringFormat

Working with Strings

Let us first see what we can do using StringFormat for our strings? We can use various string formats mentioned here in MSDN document. Take reference from it if you want. So, start with a simple example.

At the first step, we will create a DependencyProperty of type string in our code behind called "Text". Then we will add the following code in our XAML page:

 
<TextBlock>
    <Run Text="Normal string: "/>
    <Run Text="{Binding Text, ElementName=userControl}"/>
</TextBlock>
<TextBlock>
    <Run Text="String with atleast 15 characters length: "/>
    <Run Text="{Binding Text, StringFormat=\{0\,15\}, ElementName=userControl}"/>
</TextBlock>
<TextBlock>
    <Run Text="String with atleast 25 characters length: "/>
    <Run Text="{Binding Text, StringFormat=\{0\,25\}, ElementName=userControl}"/>
</TextBlock>
<TextBlock>
    <Run Text="Text with quote: "/>
    <Run Text="{Binding Text, StringFormat='The string &quot;\{0\}&quot; inside a quot',
                              ElementName=userControl}"/>
</TextBlock>

The first TextBlock will show a normal string in the UI. The 2nd one will have total 15 characters length and if our text is less than 15, it will show a blank space of the remaining length at the front. The 3rd example will show the same case but for 25 characters. In this case, it will have more space at the front. The 4th example will show a concatenated string in the UI with a quot. Remember that, you have to specify a valid ASCII value there.

The above code will render the following UI in the screen:

image

Working with Numbers


As shown above, you can format a number too. Read the MSDN document here to know more about the format of the same.

First of all, create a DependencyProperty for our example which will return a numeric value. Now, use the below example to learn about it's use in XAML:

 
<TextBlock>
    <Run Text="Normal Number: "/>
    <Run Text="{Binding Number, ElementName=userControl}"/>
</TextBlock>
<TextBlock>
    <Run Text="Above number with 2 decimal point: "/>
    <Run Text="{Binding Number, StringFormat=\{0:n2\}, ElementName=userControl}"/>
</TextBlock>
<TextBlock>
    <Run Text="Above number with 4 decimal point: "/>
    <Run Text="{Binding Number, StringFormat=\{0:n4\}, ElementName=userControl}"/>
</TextBlock>
<TextBlock>
    <Run Text="Above number with 10 Zero place holder: "/>
    <Run Text="{Binding Number, StringFormat=\{0:0000000000\}, ElementName=userControl}"/>
</TextBlock>

We used {0:nx} to format a numeric value where 'n' formats it as numeric and 'x' represents no. of decimal point.

In this example, we will 1st see the number in normal format. The 2nd example will show the same number in two decimal point. The 3rd example showcases it with 4 decimal point. The 4th one puts zero as place holder of 10 digits. If the number is less than the specified length, it will show zero's preceding the original no.

Let's have a demo of the above code here:


image

You can see here that, as the original no. is of 4 digits, it adds 6 zeros in front of the no. to make it a 10 digit number.

Working with Currencies


Let's have a demo on currency too. This will localize the currency based on the rule already set in the client system. We will use the same property used in the previous point.

We will use the following XAML code to format our currency value, to demonstrate the example:

 
<TextBlock>
    <Run Text="In Currency with zero decimal point: "/>
    <Run Text="{Binding Number, StringFormat=\{0:c0\}, ElementName=userControl}"/>
</TextBlock>
<TextBlock>
    <Run Text="In Currency with two decimal point: "/>
    <Run Text="{Binding Number, StringFormat=\{0:c2\}, ElementName=userControl}"/>
</TextBlock>

We will format the Number as Currency by specifying the StringFormat as {0:cx} where 'c' defines the currency format and 'x' represents the decimal point. In the 1st TextBlock, we will have a currency with zero decimal point and in the 2nd one will have a two decimal point.

Let's see the demo of the above example here:

image

As the above example was run in my machine (in India), hence you can notice that it shows the value in Indian currency format (Rs.). If you run it in different location having a different localization, it will show the currency in that format only.

Working with DateTime


Working with DateTime is also similar to that. If you are familiar with the formats mentioned in MSDN documentation, you can easily format your DateTime accordingly. Find the valid formats for DateTimehere. I am not going to discuss more on the format but will give you some example which you can use to apply different styles.

Let us use the following XAML code:

 
<TextBlock>
    <Run Text="Full date/time pattern (short time): "/>
    <Run Text="{Binding DateTime, StringFormat=f, ElementName=userControl}"/>
</TextBlock>
<TextBlock>
    <Run Text="Full date/time pattern (long time): "/>
    <Run Text="{Binding DateTime, StringFormat=F, ElementName=userControl}"/>
</TextBlock>
<TextBlock>
    <Run Text="Short date/time pattern (short time): "/>
    <Run Text="{Binding DateTime, StringFormat=g, ElementName=userControl}"/>
</TextBlock>
<TextBlock>
    <Run Text="Short date/time pattern (long time): "/>
    <Run Text="{Binding DateTime, StringFormat=G, ElementName=userControl}"/>
</TextBlock>

The 1st example will show the DateTime in full date and short time format, the 2nd example show both of them in long format. 3rd example will show both the date and time in short format and the 4th one will format the date in short pattern and the time in long pattern.

See the demonstration of the above code here:

image

All these values depends on your machine configuration. Hence, you may notice a different thing based on your localization settings in your computer.

 

In India generally we will get itemised bill for postpaid connections and not for prepaid bills.
Incase if you need prepaid bills for a particular month, airtel will send prepaid bill to your email address when you request them. You will be charged Rs.50/- for this service. charging is done through deducting in your prepaid account balance. ( This charge is when i am writing this article  Feb 2011).


send sms with below contents to the number 121


EPREBILL month_name  mail_id

Ex -
EPREBILL July user@mail.com

 

Referred URL
http://www.sqlservercentral.com/articles/Administration/72835/

In famous sci-fi Iron Man series Justin Hammer said "I love peace, but we live in a world of grave threats. Threats that Mr. Stark will not always be able to foresee." The statement is so true for the DBA's world where there are potential threats to data security. There is a constant fear of losing data because of the mistakes of some developer or support person.

This is a scenario I encountered recently and I thought of documenting it. This is a rare situation but we must be ready to face it if it occurs. I had to move the user database files for my TestDB to a new partition on the G:\ drive and I decided to also move tempdb to the G:\ drive at the same time. I used the code below to move the following files.

For TestDB:

Alter Database Testdb Modify File (Name=TestDB, FileName ='G:\Data\TESTDB.MDF')
Alter Database Testdb Modify File (Name=TestDB_log, FileName ='G:\Data\TestDB_log.ldf')

The output of the this code is shown in the screen shot below:


Zoom in  |  Open in new window

For tempdb I executed:

Alter Database tempdb Modify File (Name=tempdev, FileName ='G:\Data\tempdb.mdf')
Alter Database tempdb Modify File (Name=templog, FileName ='G:\Data\templog.ldf')

The output of the that code is shown in the screen shot below:


Zoom in  |  Open in new window

The SQL Server instance was stopped and the files for the user database (TestDB ) were physically moved to the new directory (G:\Data). The tempdb database files are created every time the SQL Server is restarted so there was no need to move those database files. The SQL Server instance was started and then a query was executed on the TestDB as written below.

select name,address into #table from dbo.contact
select * from #table

The output of the code above is shown in the screen shot below:


Zoom in  |  Open in new window

I had an issue one fine day when I realized that I had run out of space on my workstation's C:\ drive. I went to the Disk Management utility and deleted the G: partition to free up space. I then extended the C: partition. I then tried to open SSMS and found that the SQL Server was not started. I opened up SQL Server Configuration Manager to see the state of the SQL Server. The server was in auto start mode, but it was not running. I tried to start the server, and it did not show any error, but the server did not start. I went to the Windows error log and found the error shown below.

CREATE FILE encountered operating system error 3(The system cannot find the path specified.) while attempting to open or create the physical file 'G:\Data\tempdb.mdf'.

The issue was tempdb database files had been moved to G:\Data\ and that did not exist anymore. When SQL Server tried to restart and create tempdb, it failed. Now I had to bring the SQL Server up somehow and change the file path of tempdb to its default path. To do this, I had to start the SQL Server in single user mode and then make the changes. I stopped the SQL Server Agent from the configuration manager. I opened a command prompt and ran the code below to switch on the SQL Server with minimal configuration.

cd C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn
sqlservr.exe -f

This started the SQL Server in the minimal configuration single user mode as is shown in the screen shot below.


This started SQL Server in single user mode. I opened a new query window in SSMS and connected to the master database and then altered tempdb to point to a physically existing disk folder as shown below.

alter database tempdb move file (filename=tempdev, FileName ='C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\tempdb.mdf')
alter database tempdb move file (filename=templog, FileName ='C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\templog.ldf')

I got the message that the tempdb has been re-configured and that the change will take place when SQL Server is restarted as shown in the screen shot.


Zoom in  |  Open in new window

I closed the query window and the command line that was still running. I started the SQL Server instance again and this time it worked. After the server came up I restored the user database from a backup file using SSMS and executed the same query on the database to find the same result as shown below.


Zoom in  |  Open in new window

Newer Posts
Older Posts

Search this Site

Translate Articles

Total Posts

Total Pageviews


Contributors

My photo
Jay Srinivasan
Professional: I'm a Software Techie, Specialized in Microsoft technologies. Worked in CMM Level 5 organizations like EPAM, KPMG, Bosch, Honeywell, ValueLabs, Capgemini and HCL. I have done freelancing. My interests are Software Development, Graphics design and Photography.
Certifications: I hold PMP, SAFe 6, CSPO, CSM, Six Sigma Green Belt, Microsoft and CCNA Certifications.
Academic: All my schooling life was spent in Coimbatore and I have good friends for life. I completed my post graduate in computers(MCA). Plus a lot of self learning, inspirations and perspiration are the ingredients of the person what i am now.
Personal Life: I am a simple person and proud son of Coimbatore. I studied and grew up there. I lost my father at young age. My mom and wife are proud home-makers and greatest cook on earth. My kiddo in her junior school.
Finally: I am a film buff and like to travel a lot. I visited 3 countries - United States of America, Norway and United Kingdom. I believe in honesty after learning a lot of lessons the hard way around. I love to read books & articles, Definitely not journals. :)
View my complete profile

Certifications

Certifications

My Favorite Links

  • Saran & Akshu Links
  • Saran Kitchen Hut
  • World of Akshu
  • Ashok Raja Blog

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Contact Form

Name

Email *

Message *

Connect with Me

Blog Archive

  • ►  2025 (48)
    • ►  June (7)
    • ►  May (26)
    • ►  April (1)
    • ►  March (3)
    • ►  February (1)
    • ►  January (10)
  • ►  2024 (134)
    • ►  December (3)
    • ►  November (8)
    • ►  October (11)
    • ►  September (2)
    • ►  August (1)
    • ►  July (39)
    • ►  June (8)
    • ►  May (4)
    • ►  April (9)
    • ►  March (6)
    • ►  February (33)
    • ►  January (10)
  • ►  2023 (16)
    • ►  December (12)
    • ►  August (2)
    • ►  March (1)
    • ►  January (1)
  • ►  2022 (14)
    • ►  December (1)
    • ►  August (6)
    • ►  July (3)
    • ►  June (2)
    • ►  February (1)
    • ►  January (1)
  • ►  2021 (16)
    • ►  December (1)
    • ►  November (2)
    • ►  October (2)
    • ►  August (1)
    • ►  July (2)
    • ►  June (2)
    • ►  May (2)
    • ►  March (2)
    • ►  February (1)
    • ►  January (1)
  • ►  2020 (36)
    • ►  December (1)
    • ►  November (15)
    • ►  October (2)
    • ►  September (1)
    • ►  July (1)
    • ►  June (2)
    • ►  May (4)
    • ►  March (2)
    • ►  February (6)
    • ►  January (2)
  • ►  2019 (14)
    • ►  December (3)
    • ►  November (1)
    • ►  September (2)
    • ►  August (1)
    • ►  June (1)
    • ►  May (3)
    • ►  March (2)
    • ►  January (1)
  • ►  2018 (61)
    • ►  November (3)
    • ►  October (4)
    • ►  September (4)
    • ►  August (5)
    • ►  July (4)
    • ►  June (4)
    • ►  May (7)
    • ►  April (7)
    • ►  March (5)
    • ►  February (1)
    • ►  January (17)
  • ►  2017 (55)
    • ►  December (1)
    • ►  November (7)
    • ►  October (7)
    • ►  September (8)
    • ►  July (4)
    • ►  June (7)
    • ►  May (4)
    • ►  April (4)
    • ►  March (1)
    • ►  February (2)
    • ►  January (10)
  • ►  2016 (45)
    • ►  December (1)
    • ►  November (5)
    • ►  October (2)
    • ►  September (7)
    • ►  August (3)
    • ►  July (3)
    • ►  June (1)
    • ►  May (3)
    • ►  April (5)
    • ►  March (3)
    • ►  February (3)
    • ►  January (9)
  • ►  2015 (88)
    • ►  December (5)
    • ►  November (2)
    • ►  October (6)
    • ►  September (6)
    • ►  August (3)
    • ►  July (6)
    • ►  June (7)
    • ►  May (12)
    • ►  April (6)
    • ►  March (11)
    • ►  February (10)
    • ►  January (14)
  • ►  2014 (159)
    • ►  December (16)
    • ►  November (13)
    • ►  October (42)
    • ►  September (12)
    • ►  August (19)
    • ►  July (3)
    • ►  June (17)
    • ►  May (10)
    • ►  April (12)
    • ►  March (7)
    • ►  February (4)
    • ►  January (4)
  • ►  2013 (192)
    • ►  December (7)
    • ►  November (2)
    • ►  October (3)
    • ►  September (10)
    • ►  August (25)
    • ►  July (17)
    • ►  June (22)
    • ►  May (22)
    • ►  April (24)
    • ►  March (17)
    • ►  February (22)
    • ►  January (21)
  • ►  2012 (204)
    • ►  December (21)
    • ►  November (35)
    • ►  October (47)
    • ►  September (27)
    • ►  August (6)
    • ►  July (21)
    • ►  June (16)
    • ►  May (7)
    • ►  April (9)
    • ►  March (4)
    • ►  February (3)
    • ►  January (8)
  • ▼  2011 (70)
    • ►  December (8)
    • ►  November (5)
    • ►  October (3)
    • ►  September (2)
    • ►  August (7)
    • ►  July (3)
    • ►  June (30)
    • ▼  May (3)
      • Formatting text in Silverlight XAML using StringFo...
      • How to get Airtel Prepaid itemised monthly bill
      • TempDB Deleted Accidentally
    • ►  April (3)
    • ►  March (1)
    • ►  February (3)
    • ►  January (2)
  • ►  2010 (30)
    • ►  December (1)
    • ►  September (4)
    • ►  August (1)
    • ►  July (1)
    • ►  June (1)
    • ►  May (4)
    • ►  April (6)
    • ►  March (5)
    • ►  February (2)
    • ►  January (5)
  • ►  2009 (40)
    • ►  December (4)
    • ►  November (6)
    • ►  October (4)
    • ►  September (5)
    • ►  August (4)
    • ►  July (3)
    • ►  June (4)
    • ►  May (8)
    • ►  March (1)
    • ►  February (1)
  • ►  2008 (6)
    • ►  December (1)
    • ►  September (1)
    • ►  May (1)
    • ►  April (2)
    • ►  February (1)
  • ►  2007 (7)
    • ►  December (1)
    • ►  November (2)
    • ►  October (1)
    • ►  July (1)
    • ►  May (2)

Recent Posts

Followers

Report Abuse

FOLLOW ME @INSTAGRAM

Popular Posts

  • Stay Wow - Health Tips from Sapna Vyas Patel
    Referred URL https://www.facebook.com/sapnavyaspatel WATCH WEIGHT LOSS VIDEO: http://www.youtube.com/ watch?v=S_dlkjwVItA ...
  • Calorie Count chart For food and drinks
    Referred URL http://deepthidigvijay.blogspot.co.uk/p/health-diet-calorie-charts.html http://www.nidokidos.org/threads/37834-Food-Calorie-...
  • SharePoint 2010 Interview Questions and Answers
    Referred URL http://www.enjoysharepoint.com/Articles/Details/sharepoint-2010-interview-questions-and-answers-148.aspx 1.What is SharePoint...
  • 150 Best Windows Applications Of Year 2010
    Referred URL : http://www.addictivetips.com/windows-tips/150-best-windows-applications-of-year-2010-editors-pick/?utm_source=feedburner...
  • Web Developer Checklist by Mads Kristensen
    Referred Link -  http://webdevchecklist.com/ Web Developer Checklist Get the extension  Chrome  |  Firefox  |  Edge Menu Bes...
  • WCF and REST Interview Questions
    What is WPF? The Windows Presentation Foundation (WPF) is a next generation graphics platform that is part of...
  • Remove double tap to unlock feature on samsung galaxy core2
    Double tap to unlock is a feature of Talkback, so if your will disable Talkback, double tap to unlock will also be disabled. To disable doub...
  • Difference Between Content Editor and Script Editor webpart
    Referred Link -  http://jeffas.com/content-editor-vs-script-editor-webpart/ Content editor web part is a place holder for creating rich ...
  • SPFolder related operations in SharePoint
      1) Get SPListItem(s) of a particular SPFolder SPList splist; SPFolder spfolder; //Get the required folder instance SPQuery spquery = new ...

Comments

Created with by BeautyTemplates | Distributed by blogger templates