Posts

Showing posts from June, 2012

WPF DataGrid change cell value based on underlying data object

XAML <Window x:Class=" DataGridCellBackground.MainWindow " xmlns=" http://schemas.microsoft.com/winfx/2006/xaml/presentation " xmlns:x=" http://schemas.microsoft.com/winfx/2006/xaml " xmlns:DataGridCellBackground=" clr-namespace:DataGridCellBackground " Title=" MainWindow " Height=" 350 " Width=" 525 " DataContext=" {Binding RelativeSource={RelativeSource Self}} "> <Window.Resources> <DataGridCellBackground:DataGridCellValueConverter x:Key=" dataGridCellValueConverter "/> </Window.Resources> <Grid> <DataGrid ItemsSource=" {Binding Data} " Width=" 400 " Height=" 200 " CanUserAddRows=" False "> <DataGrid.CellStyle> <Style TargetType=" {x:Type DataGridCell} "> <Setter Property=" Template "> <Setter.Value&g

WPF Toggle button group

<StackPanel> <RadioButton Content=" Left " Style=" {StaticResource {x:Type ToggleButton}} " /> <RadioButton Content=" Right " tyle=" {StaticResource {x:Type ToggleButton}} " /> </StackPanel>

WPF DataGrid change cell style based on underlying data object

XAML < Window x : Class = "DataGridCellBackground.MainWindow" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns : x = "http://schemas.microsoft.com/winfx/2006/xaml" xmlns : DataGridCellBackground = "clr-namespace:DataGridCellBackground" Title = "MainWindow" Height = "350" Width = "525" DataContext = "{Binding RelativeSource={RelativeSource Self}}" > < Window.Resources > < DataGridCellBackground : DataGridCellBackgroundConverter x : Key = "dataGridCellBackgroundConverter" /> </ Window.Resources > < Grid > < DataGrid ItemsSource = "{Binding Data}" Width = "400" Height = "200" > < DataGrid.CellStyle > < Style TargetType = "{x:Type DataGridCell}" > < Setter Property = "Background" >

HTML Table css style reference

Image
< html > < head > < link rel = "stylesheet" href = "table.css" /> </ head > < body > < table class = "table1" > < thead > < tr > < th width = "120px" > </ th > < th width = "100px" > Column1 </ th > < th width = "100px" > Column2 </ th > </ tr > </ thead > < tbody > < tr > < th scope = "row" > Row1 </ th > < td > 1.1 </ td > < td > 1.2 </ td > </ tr > < tr > < th scope = "row" > Row2 </ th > < td > 2.1 </ td > < td > 2.2 </ td > </ tr > </ tbody > < tfoot >

C# Regex replace

[Test] public void TestRegexReplace() { //replace A or B with X after \Date\ var pattern = @" \b(?<=\\Date\\)(A|B)\b "; Assert.AreEqual( @" c:\temp\Date\X\SubFolder\ ", Regex.Replace(@" c:\temp\Date\A\SubFolder\ ", pattern, m => " X ")); Assert.AreEqual( @" c:\temp\Date\X\SubFolder\ ", Regex.Replace(@" c:\temp\Date\B\SubFolder\ ", pattern, m => " X ")); Assert.AreEqual( @" c:\temp\Date\C\SubFolder\ ", Regex.Replace( @" c:\temp\Date\C\SubFolder\ ", pattern, m => " X ")); //or the simple way :) pattern = @" \\Date\\[AB]\\ "; Assert.AreEqual( @" c:\temp\Date\X\SubFolder\ ", Regex.Replace(@" c:\temp\Date\A\SubFolder\ ", pattern, m => @" \Date\X\ ")); Assert.AreEqual( @" c:\temp\Date\X\SubFolder\ ", Regex.Replace(@" c:\temp\Date\B\SubFolder\ ", pattern, m => @&quo

Update Log4Net file name programmatically

//update log file name public static bool ChangeLogFileName( string appenderName, string newFilename) { var rootRepository = log4net.LogManager.GetRepository(); foreach (var appender in rootRepository.GetAppenders()) { if (appender.Name.Equals(appenderName) && appender is log4net.Appender.FileAppender) { var fileAppender = appender as log4net.Appender.FileAppender; fileAppender.File = newFilename; fileAppender.ActivateOptions(); return true ; // Appender found and name changed to NewFilename } } return false ; // appender not found } //usage ChangeLogFileName(" RollingFileAppender ", " MyLogName.log "); Sample log4net configuration from App.config, for more info see this post //App.config configuration <? xml version="1.0" ?> < configuration > < configSections > < section name = "log4net" type = "log4net.Config.Log4NetConfig