using System.Text; using System.Diagnostics; namespace GenApp.Utils.Theory { /// <summary> /// This is fake class for quick copy paste. Usage: /// type HowTo. - the intellisense will display the names you have figured out for each fake method /// select the name from the , click in it , right button , G , will get you there , /// copy paste the text , Alt + F, C to close and remember to delete the fake call. /// </summary> public class HowTo { public static void UseRegexesWithWhiteSpace () { //how-to use regexes with white space // Regex re = new Regex( // @" # This pattern matches Foo // (?i) # turn on insensitivity // # The Foo bit // \b(Foo)\b " // , RegexOptions.IgnorePatternWhitespace ) ; // for ( Match m = re.Match( "foo bar Foo" ) ; m.Success ; m = m.NextMatch() ; } //eof method public static void DisplayJavaScriptConfirmationDialog () { //Active_chkbox.Attributes.Add("OnClick" , "return (confirm('Do you want do disable this user'));"); } //eof method public static void RegisterPageStartUpScript () { //how-to Page.RegisterStartupScript(@"startup",@"<script>alert('Thank you!');</script>"); //string JaScript = "<script language=’javascript’> alert('User Details saved successfully') </script> " ; //Response.Write( JaScript ); } //eof method RegionsterPageStartUpScript public static void AddCallingMethodNameToDebug () { string code = @" System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(); string mName = st.GetFrame(1).GetMethod().Name; "; } //eof method AddCallingMethodNameToDebug public static void SettersAndGetters () { string help = @" how-to generate those in textpad F8 how-to Generate member accessors , properties for C# asp.net with textpad how-to setters and getters find:^(.*)$ replace:private string _\1 ; \n public string \1 { \n \t\t get { return _\1 ; } \n \t\t set { _\1 = value ; } \n } //comm -- eof \1 property \n\n find:^(.*) (.*)$ private string s\1 ; \n public string \1 { \n \t\t get { return s\1 ; } \n \t\t set { s\1 = value ; } \n } //comm -- eof \1 property \n\n FIND:first remove all the [] from the copy paste of the table create screipt ^\t\[([a-zA-Z_]*)\](.*)$ FIND type and var ^(.*) (.*)$ REPLACE Properties #region \2 \n private \1 _\2 ; \npublic \1 \2 { \n \t\t get { return _\2 ; } \n \t\t set { _\2 = value ; } \n } //eof property \2 \n\n\n #endregion \2 \n\ //for the constructor _\2= this.\2 ; //for the passing to the constuctor \1 _\2 , /* ^(.*) (.*)$ #region \2 \nprivate List<\1> _\2;\npublic List<\1> \2 { get { return _\2; } set { _\2 = value; } }\n#endregion \2\n\n "; } //eof method SettersAndGetters public static void ListAllDbObjects () { /* --HOW-TO LIST ALL PROCEDURE IN A DATABASE select s.name from sys.objects s where type = 'P' or type='UP' -- GET THE GENERATED ONES ONLY select s.name from sysobjects s where type = 'P' and s.name like '%gsp%' --HOW-TO LIST ALL TRIGGERS BY NAME IN A DATABASE select s.name from sysobjects s where type = 'TR' --HOW-TO LIST TABLES IN A DATABASE select s.name from sysobjects s where type = 'U' --how-to list all system tables in a database select s.name from sysobjects s where type = 's' --how-to list all the views in a database select s.name from sysobjects s where type = 'v' Similarly you can find out other objects created by user, simple change type = C = CHECK constraint D = Default or DEFAULT constraint F = FOREIGN KEY constraint L = Log FN = Scalar function IF = In-lined table-function P = Stored procedure PK = PRIMARY KEY constraint (type is K) RF = Replication filter stored procedure S = System table TF = Table function TR = Trigger U = User table ( this is the one I discussed above in the example) UQ = UNIQUE constraint (type is K) V = View X = Extended stored procedure */ } //eof method public static void GetProcedureMetaData () { string answer = @" select PARAMETER_NAME as 'COLUMN_NAME', DATA_TYPE , CHARACTER_MAXIMUM_LENGTH AS 'MAX_LENGTH', IS_RESULT , PARAMETER_MODE from INFORMATION_SCHEMA.PARAMETERS where SPECIFIC_NAME='Login_Check' Select * from INFORMATION_SCHEMA.Routines --returns stored procedures and functions exec sp_HelpText 'Login_Check' "; answer = string.Empty; } //eof method public static void GetRowColumnValuesFromDs () { //(ds.Tables["TableName"].Rows[0]["ColumnName"] == DBNull.Value) ? false : (bool)ds.Tables["TableName"].Rows[0]["ColumnName"]; } //eof method public static void CopyMeAsTemplateMethod () { } //eof method public static void ReflectionExample () { //Type objectType = testObject.GetType(); //ConstructorInfo[] info = objectType.GetConstructors(); //MethodInfo[] methods = objectType.GetMethods(); //// get all the constructors //Console.WriteLine("Constructors:"); //foreach (ConstructorInfo cf in info) //{ // Console.WriteLine(cf); //} //Console.WriteLine(); //// get all the methods //Console.WriteLine("Methods:"); //foreach (MethodInfo mf in methods) //{ // Console.WriteLine(mf); //} } public static void shortcuts () { string _shortcuts = @" //how-to shortcuts Ctrl + Shift + F -- recursive find F3 -- find next occurence Ctrl + H -- find and replace Ctrl + M + M -- collapse method Ctrl + B --- set a break point CTRL + “-” and CTRL + SHIFT + “-” -- web browser like backward and forward in code Ctrl + Tab --- shift tabs Shift + F5 --- stop debugging Ctrl + I --- fast search F5 -- start debugging Tryf = try and finally block Prop = property with get and set accessor Switch = switch statement with default Alt + W , L -- close all windows Alt + W , 1 -- open the first window Alt + F , F , 1 -- open the latest file I closed Ctrl + F2 , Tab -- go to the methods dropdown , type a letter to get to the name of the method Alt + L --- select the Solution Explorer Ctrl + Shift + Z -- press 2 (needs arsclip (google download arsclip)) -- get the second latest entry from my clipboard "; } //eof shortcuts public static void redirectToCurrentUrl () { string _redirectToCurrentUrl = @" Response.Redirect ( System.IO.Path.GetFileName ( System.Web.HttpContext.Current.Request.Url.AbsolutePath ) , false ); "; } //eof method public static void formTypes () { string _formTypes = @" //how-to forms 1 - Empty Search Form , 2 - Filled Form , 3 - Empty New form ( new Margin Data , new Project ) //how-to formTypes //, 4 - filled search form from get by id procedure // 5 - FilledSearchForm (coming from params) "; } //eof formTypes public static void GetTheFileNameWithoutTheExtension () { /* System.IO.Path.GetFileNameWithoutExtension ( System.Web.HttpContext.Current.Request.Url.AbsolutePath ) ); */ } //eof methoed public static void GetThePhysicalRootPathNoExtension () { //how-to get the physical root path on the file system of the application //Utils.Dbg.Debugger.WriteIf ( "My rootPath is " + rootPath ); } //eof method public static void AccessConfVariables () { //how-to access conf variables BL.Conf.Instance.Vars [ "varName" ] would give you "theVarName ; } //eof method public static void GetRowColumnValue () { //how-to get row column value //(ds.Tables["TableName"].Rows[0]["ColumnName"] == DBNull.Value ) ? false : (bool)ds.Tables["TableName"].Rows[0]["ColumnName"] ; } //eof method public static void GenerateExtendedPropertiesForATable () { //table column //find:^(.*) (.*)$ //Replace: //EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'title="\2",visible="1",fs="Basic Details",readonly="1"' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'\1', @level2type=N'COLUMN',@level2name=N'\2' } //eof method public static void RedirectToTheCurrentURL () { //how-to redirect to current url = users.aspx or projects.aspx /* Response.Redirect( System.IO.Path.GetFileName ( System.Web.HttpContext.Current.Request.Url.AbsolutePath ) , false ); */ } //eof method public static void THEORY () { //EVENTS AND DELEGATES IN ASP.NET -- http://msdn.microsoft.com/en-us/library/17sde2xt.aspx } //eof method public static void ReplaceDebugging () { /* find : replace ^(.*)([^\/\/])(Utils\.Debugger) \t\t\t\t\t//Utils.Dbg.Debugger */ } public static void UseStringBuilderInsteadOfString () { //Bad string s = "This "; s += "is "; s += "not "; s += "the "; s += "best "; s += "way."; //Good: StringBuilder sb = new StringBuilder (); sb.Append ( "This " ); sb.Append ( "is " ); sb.Append ( "much " ); sb.Append ( "better. " ); } //eof method public static void AssignValueIfNotNull ( string SomeValue ) { //Long SomeObject SomeObject = new SomeObject (); if (SomeValue == null) SomeObject.Value = null; else SomeObject.Value = SomeValue; //Instead of this: SomeObject.Value = SomeValue ?? null; } public static void MeasureMethodPerformance () {//source:http://stackoverflow.com/questions/28637/is-datetime-now-the-best-way-to-measure-a-functions-performance Stopwatch sw = new Stopwatch (); sw.Start (); // Do Work sw.Stop (); string StrDebug = string.Format ( "Elapsed time: {0}", sw.Elapsed.TotalMilliseconds ); //Utils.Dbg.Debugger.WriteIf ( StrDebug ); } //eof method public static void GenerateResxFileOutOfListing () { /* FIND: ^(.*)$ REPLACE: <data name="\1" xml:space="preserve"> \n <value>value</value>\n <comment>comment</comment> \n</data>\n */ } //eof method public static void InsertCodeSnippet () { /*CopyPasteTheFollowingCode into this folder (your milleage may vary ; ) * C:\Users\%userName%\Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets * Save it as a file with the same title and type *.snippet <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title> ThisIsTheTitleVisibleForIntellisense </Title> </Header> <Snippet> <Code Language="CSharp"> <![CDATA[ Put the code here ]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets> Use by : Type CTRL+K, CTRL+X, arrows to navigate , */ } } //eof class public class SomeObject { public string Value { get; set; } } //eof class } //eof namespace
Getting the Current TabItem when the Tab is not selected in WPF
-
[image: Banner]
This is a quick reminder to self on how to retrieve a TabItem from a WPF
TabControl *when the tab is not currently selected* because I ru...
1 month ago
No comments:
Post a Comment
- the first minus - Comments have to be moderated because of the spammers
- the second minus - I am very lazy at moderating comments ... hardly find time ...
- the third minus - Short links are no good for security ...
- The REAL PLUS : Any critic and positive feedback is better than none, so your comments will be published sooner or later !!!!