WPF add ScrollViewer to UniformGrid programatically

private static TabItem RenderSingleRow(String tabName, DataTable singleRow, int rowNumber)
{
try
{
var currentTabItem = new TabItem {Name = tabName, Header = tabName};

var scrollViewer = new ScrollViewer
{
CanContentScroll = true,
HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
VerticalScrollBarVisibility = ScrollBarVisibility.Auto
};

var mainUniformGrid = new UniformGrid
{
Columns = 2,
VerticalAlignment = VerticalAlignment.Top,
Margin = UniformGridMargin
};

foreach (DataColumn singleRowColumn in singleRow.Columns)
{
StackPanel singleStackPanel = CreateSingleStackPanel(singleRowColumn.ColumnName,
singleRow.Rows[rowNumber][singleRowColumn].
ToString());
if (singleStackPanel != null) mainUniformGrid.Children.Add(singleStackPanel);
}

// CurrentTabItem.Content = MainUniformGrid;
scrollViewer.Content = mainUniformGrid;
currentTabItem.Content = scrollViewer;
return currentTabItem;
}
catch
{
return null;
}
}

Advertisement

C# Code Snippets

 
Return Namespace/Class/MethodName as a string

return string.Format(“{0}.{1}.{2}()”, MethodBase.GetCurrentMethod().ReflectedType.Namespace, MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name);

 

Entity Framework 4 Mapping a Stored Procedure

Update the Model from the database by selecting the Stored Procedure and including it in the model.

Right click on the design surface and choose Add Function Import, select the stored procedure from the list and click Get Column Information, then click the Create New Complex Type button so that there’s an entity to map to.

http://weblogs.asp.net/kencox/archive/2009/11/25/using-a-stored-procedure-in-entity-framework-4.aspx

Getting CC.Net working on our DEV box

Install Cruise Control on the Server and install as service
Configure the ccnet.config with a Project proj1
Create a working directory
In the working directorybin directory, install nant, nantcontrib, visualsvn
Create a project directory in the working directory
proj1
In the proj1 directory, create a nant build script
Start the Cruise Control service

Nant template

<?xml version=1.0?>
<
project name=MyProject default=production>
    <
description>MyProject NANT build script</description>
    <!–
properties used in this file –>
    <!–
this property will be overridden by cruisecontrol –>
    <
property name=ccnet.label value=0/>
    <!–
name of solution/project
    Assume Virtual directory  == solution == project name
    (if other projects, manually add webmap/map)
–>
    <
property name=build.projname value=MyProjectName/>
    <!–
build.outputpath – where the built code is put (see also project@basedir above) –>
    <
property name=build.rootpath value=C:Build/>
    <
property name=build.outputpath value=${build.rootpath}Deploy/>
    <
property name=build.srcpath value=${build.rootpath}Src/>
    <!–
build.solutionpath –>
    <
property name=build.solutionpath value=${build.rootpath}Src/>
    <
property name=build.localsolutionpath value=C:Visual Studio ProjectsMyProject/>
    <!–
VSS properties –>
    <
property name=build.srcsafeini value=sshostssdirectorysrcsafe.ini/>
    <
property name=build.srcsafepath value=$/${build.projname}/>
    <
property name=build.VssUserName value=VssUserName/&
gt;
    <!–
default task – build it and create deployment
    See also the task “full” below (used by CC.Net)
    –>
    <
target name=production description=Build solution and copy production files>
        <!–
default project task- runs build, then deploy–>
        <
call target=clean/>
        <
call target=build/>
        <
call target=deploy/>
    </
target>
    <!–
clean out the deploy directory–>
    <
target name=clean description=Copy production files>
        <
delete dir=${build.outputpath} failonerror=false/>
    </
target>
    <!–
build target – the solution –>
    <
target name=build description=Compile solution using Release configuration>
        <
solution solutionfile=${build.localsolutionpath}${build.projname}.sln
                  
configuration=Release outputdir=${build.outputpath}${build.projname}bin>
            <
webmap>
                <!–
remap the url in solution to a local directory –>
                <
map url=http://localhost/${build.projname}/${build.projname}.vbproj
                    
path=${build.srcpath}${build.projname}${build.projname}.vbproj/>
            </
webmap>
            <
excludeprojects>
                <!–
include name=”TestNunitTests.vbproj”/–>
            </
excludeprojects>
        </
solution>
    </
target>
    <!–
create a deployment –>
    <
target name=deploy description=Copy production files>
        <!–
Copy build results to Deploy folder –>
        <
copy todir=${build.outputpath}>
            <
fileset basedir=${build.srcpath}>
                <
include name=**.aspx/>
                <
include name=**.html/>
                <
include name=**.config/>
                <
include name=**.gif/>
                <
include name=**.jpg/>
                <
include name=**.css/>
                <
include name=**.js/>
            </
fileset>
        </
copy>
        <!–
Reset attributes to Normal –>
        <
attrib normal=true>
            <
fileset basedir=${build.outputpath}>
                <
include name=**/>
            </
fileset>
        </
attrib>
        <!–
how to change web.config
         <xmlpoke file=”BuildDeployWeb.config”
         xpath=”/configuration/Templates/add
         [@key=’TemplatesFolder’]/@value”
         value=”D:inetpubwwwrootvdirTemplates” />
–>
    </
target>

    <!– This is called from Cruise Control –>
    <
target name=full description=Build solution and copy production files>
        <!–
default project task- runs build, then deploy–>
        <
delete dir=${build.srcpath}
failonerror=false/>
        <
call target=getDependency/>
        <
call target=getLatest/>
        <
call target=buildFromVSS/>
        <
call target=deployVSS/>
        <
call target=FXCopReport/>
    </
target>
    <!–
source safe task–>
    <
target name=getDependency description=Get a dependency from source safe>
        <
mkdir dir=${build.srcpath} failonerror=false/>
        <
vssget username=${build.VssUserName} password=“” localpath=${build.srcpath}
                
recursive=true replace=true writable=true
                dbpath=${build.srcsafeini} path=${build.srcsafepath}/Dependency/>
        <
solution solutionfile=${build.solutionpath}Dependency.sln
                  
configuration=Release outputdir=${build.srcpath}${build.projname}bin/>
    </
target>
    <!–
source safe task–>
    <
target name=getLatest description=Get the latest version of the code from source safe>
        <
mkdir dir=${build.srcpath} failonerror=false/>
       &n
bsp;<
vssget username=${build.VssUserName} password=“” localpath=${build.srcpath}
                
recursive=true replace=true writable=true
                dbpath=${build.srcsafeini} path=${build.srcsafepath}/>
    </
target>

    <target name=buildFromVSS description=Compile solution using Release configuration>
        <
solution solutionfile=${build.solutionpath}${build.projname}.sln
                  
configuration=Release outputdir=${build.outputpath}bin>
            <
webmap>
                <!–
remap the url in solution to a local directory –>
                <
map url=http://localhost${build.projname}/${build.projname}.vbproj
                    
path=${build.srcpath}${build.projname}${build.projname}.vbproj/>
            </
webmap>
            <
excludeprojects>
                <!–
include name=”TestNunitTests.vbproj”/–>
            </
excludeprojects>
        </
solution>
    </
target>
    <!–
Copy to deployment directory and create a zip archive –>
    <
target name=deployVSS description=Copy production files>
        <!–
Copy build results to Deploy folder –>
        <
copy todir=${build.outputpath}>
            <
fileset basedir=${build.srcpath}${build.projname}>
                <
include name=**.aspx/>
                <
include name=**.html/>
                <
include name=**.config/>
                <
include name=**.gif/>
                <
include name=**.jpg/>
                <
include name=**.css/>
                <
include name=**.js/>
            </
fileset>
        </
copy>
        <!–
Reset attributes to Normal –>
        <
attrib normal=true>
            <
fileset basedir=${build.outputpath}>
                <
include name=**/>
            </
fileset>
        </
attrib>
        <
zip zipfile=${build.rootpath}backup${ccnet.label}.zip>
            <
fileset basedir=${build.outputpath}>
                <
include name=**/*/>
            </
fileset>
        </
zip>
    </
target>
    <
target name=FXCopReport>
        <
exec program=C:Program FilesMicrosoft FxCop 1.35fxcopcmd.exe
              
commandline=/f:C:BuildDeploybin${build.projname}.dll /o:C:Buildfxcop.xml
              
failonerror=false/>
    </
target>
    <!–
Check in dll into VSS –>
    <
target name=checkin description=Checkin latest dll>
        <
vsscheckin username=${build.VssUserName} password=“”
                    
localpath=${build.outputpath}${build.projname}bin${build.projname}.dll
                    
recursive=false writable=true
                    dbpath=${build.srcsafeini}
                    
path=${build.srcsafepath}/bin/${build.projname}.dll
                    
comment=ccnet build ${ccnet.label}/>
        <
vsscheckout username=${build.VssUserName} password=“”
                    
localpath=${build.outputpath}${build.projname}bin${build.projname}.dll
                    
recursive=false writable=true
                     dbpath=${build.srcsafeini}
                    
path=${build.srcsafepath}/bin/${build.projname}.dll/>
    </
target>
</
project>

log4net example

 

In a recent project, I needed to implement logging and decided to use the log4net.dll which I have seen referenced in a number of different open source projects. Here are the steps I had to taken in order to use log4net in my project:

 

1. Download the log4net.dll from http://sourceforge.net/projects/log4net/

2. Add a reference to your project that includes the downloaded log4net.dll

3. Add a log4net section to your web.config/app.config file:

<configuration>
    <configSections>
            <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
        </sectionGroup>
    </configSections>
</configuration>

4. Add a log4net.config file to your project with the following configuration:

<?xml version="1.0" encoding="utf-8"?>
<log4net debug="true">
  <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
    <param name="File" value="log4netoutput.log" />
    <param name="AppendToFile" value="true" />
    <layout type="log4net.Layout.PatternLayout">
      <param name="ConversionPattern" value="%d [%t] %-5p [%c] %m%n" />
    </layout>
  </appender>
  <root>
    <level value="DEBUG" />
    <appender-ref ref="LogFileAppender" />
  </root>
</log4net>

There are various Appenders you can create but this example uses a text file to log the results into the bin directory of the application. There are also different values that can be used as part of the ConversionPattern to get different output.

5. Be sure to change the properties of the log4net.config file in your project for the Copy to Output Directory attribute to Copy Always. I spent hours debugging my code because the config file was not being copied into the bin directory and log4net did not throw any exceptions. Since I had not used log4net before, I was making the assumption the problem was with my code and/or config file settings.

6. Here’s my code from a test method to make sure log4net is working correctly:

[Test]
public void TestLog4NetOnItsOwn()
{
    ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    XmlConfigurator.Configure(new FileInfo(Settings.Default.log4net_config_file)); 
    logger.Debug("Here is a debug log.");
}

To log results to the console, include the following line of code:

BasicConfigurator.Configure();

 

I’ve seen other posts that reference the log4net.config file in the Assembly.cs file rather than in code:

[assembly: log4net.Config.XmlConfigurator(ConfigFile="log4net.config", Watch = true)]

 

Other Posts and Resources:

http://it.toolbox.com/blogs/daniel-at-work/using-log4net-in-cnet-26794

http://geekswithblogs.net/bsherwin/archive/2008/02/15/119657.aspx