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> <ControlTemp…

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<Windowx: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:DataGridCellBackgroundConverterx:Key="dataGridCellBackgroundConverter"/></Window.Resources><Grid><DataGridItemsSource="{Binding Data}"Width="400"Height="200"><DataGrid.CellStyle><StyleTargetType="{x:Type DataGridCell}"><SetterProperty="Background"><Setter.Value><MultiBindingConverter="{StaticResource dataGridCellBackgroundConverter}"><MultiBinding.Bindings><BindingRelativeSource="{R…

HTML Table css style reference

Image
<html><head><linkrel="stylesheet"href="table.css"/></head><body><tableclass="table1"><thead><tr><thwidth="120px"></th><thwidth="100px">Column1</th><thwidth="100px">Column2</th></tr></thead><tbody><tr><thscope="row">Row1</th><td>1.1</td><td>1.2</td></tr><tr><thscope="row">Row2</th><td>2.1</td><td>2.2</td></tr></tbody><tfoot><tr><thscope

C# Regex replace

[Test] publicvoid 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 => @"\Date\X\")); Assert.AreEqual( @"c:\temp\Date\C\S…

Update Log4Net file name programmatically

//update log file namepublicstaticbool 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(); returntrue; // Appender found and name changed to NewFilename } } returnfalse; // appender not found} //usageChangeLogFileName("RollingFileAppender", "MyLogName.log");Sample log4net configuration from App.config, for more info see this post//App.config configuration <?xml version="1.0"?><configuration><configSections><sectionname="log4net"type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/></configSections><log4net>…