Archive

Posts Tagged ‘C#’

Using VisualStateManager inside DataTemplate

January 6, 2016 Leave a comment

Adaptive layout is really important while we creating windows universal apps and the
recommended way to achieve it is using RelativePanels and VisualStateManager.VisualStateGroups.

On a normal static page [where data is fixed or known for us] we can achieve it easily.
But if we are delaing with adynamic list of data or if we bind thda data to a listbox or any list its bit different.

Important point here is

we can’t directly use Adaptive concept using VisualStateManager.VisualStateGroups with objects placed inside a DataTemplate. Instead, we need to create a User Control and put the DataTemplate content inside it:

A detailed blog with proper explanation is here and it helps me a lot with my development

https://marcominerva.wordpress.com/2015/05/12/adaptive-triggers-relativepanel-and-datatemplate-in-universal-windows-platform/

Categories: Prsnl References Tags: ,

Remove Frame rate counters or black rectangles from corners while running Universal windows app

January 4, 2016 Leave a comment

While i started the development on Universal windows app and when i run the UWP app on Local machine or on emulator i noticed a black rectangle on the top right corners of application like in the image

blog_framerate

After reading few more about UWP i  realized that this is indication of frame rates and we can disable it. So to disable this Frame rate indication while running the application what we have to do is disable few lines of code from the  OnLaunched event in App.xaml.cs file

   #if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
this.DebugSettings.EnableFrameRateCounter = true;
}
#endif

Categories: Prsnl References Tags: ,

Generate word documents using OpenXML SDK

October 22, 2014 Leave a comment

Recently i came across a requirement that the application allows the user to generate the word documents for a specific report and they want the same data must follow some specific patterns .

So creating word document from scratch makes no sense and thus i forced to start look for other alternate options and came to know about OpenXML . But  only few limitted resources are available over the internet that explains the usage of this in a neat easy way fit perfect for begginers

http://www.dotnet-geek.co.uk/index.php/openxml-word-templates-processing/ 

and http://www.emoreau.com/Entries/Articles/2011/03/Using-OpenXML-to-fill-a-Word-document-from-a-Net-application.aspx

Both these are explain the concept using a desktop applicaton , but any one can easily convert it back to web app. In case th blog Urls are down can see the details of the blog in attached PDF

OpenXML Éric Moreau’s blog _ Using OpenXML to fill a Word document from a OpenXML Word templates processing _ dotNet Geek _

Categories: Prsnl References Tags: , ,

Async. Download progress bar c#

December 4, 2012 Leave a comment

The code for creating an async. download progress bar , allows user to track how much data is downloaded

WebClient client = new WebClient();

client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);

client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);

//// Starts the download

string folder_path =”Location to save file”;

client.DownloadFileAsync(new Uri(downloadUrl), folder_path,””);

void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)

{

double bytesIn = double.Parse(e.BytesReceived.ToString());

double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());

double percentage = bytesIn / totalBytes * 100;

 

downloadProgress.Text = int.Parse(Math.Truncate(percentage).ToString()).ToString()+” % finished”;

}

Categories: Prsnl References Tags: , , , ,

Check The String is a valid Excel CellName or not using c#

April 3, 2011 Leave a comment

If you want to check the validity of name of cells you enterd
This function checks given string is a range addres or not
A1:A13- valid
A1:B12 valid
A1:A-not valid
A1:aa not valid
1A:b1 –not valid.

public bool checkcellRangeValidity(string inputrange)
{ bool valid = true;
string[] parts = inputrange.Split(':');
if (parts.Length == 2)
{
if (!((validcell(parts[0])) && (validcell(parts[1]))))
valid = false;
}
else //only one part or more parts on both sides of ':'
{
valid = false;
}
return valid;
}

Give string is a valid cell or not
A1: valid
A-not valid
1 not valid
1A not valid

public bool validcell(string inputcell)
{
bool valid = true;

int count = 0;
int digitscount = 0;
int lettercount = 0;

foreach (char c in inputcell)
{
if (char.IsDigit(c))
digitscount++;

if (char.IsLetter(c))
lettercount++;

if (!char.IsLetterOrDigit(c))
{
valid = false;
break;
}

if (count == 0) //means the very first char should be letter
{
count++;
if (!char.IsLetter(c))
{
valid = false;
break;
}

}
}

if (valid)
{ //chk only if the conditions are true till
if (!((digitscount >= 1) && (lettercount >= 1)))
{
// the cell is lagging either a no or a letter

valid = false;
}
}

return valid;
}

Categories: C# Programming Tips Tags: