develop

syntaxhighlighter for wordpress

after a long search i found my prefered syntax highlighter plugin for wordpress.

here is a little list of the most used highlighters that can be found at the internet.

i choose the SyntaxHighlighter Evolved because the plugin does allow XAML code to be added to a post under the language XML and does not let wordpress interpret the <> characters in the added sourcecode.

here is a little example

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options">
  <Grid>
    <TextBlock Text="it works" />
  </Grid>
</Page>

here are the ugly code change that i mean

<page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options">
  <grid>
    <textblock Text="it works" />
  </grid>
</page>

that’s it

automatically generate wpf listview columns

this code generates automatically listview columns for all properties for the given datatype

public class BaseListView : ListView
{
  public BaseListView() {
    ItemsSourceProperty.AddOwner(typeof(BaseListView), new FrameworkPropertyMetadata(null, OnItemsSourcePropertyChanged));
  }

  private static void OnItemsSourcePropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) {
    if (e.OldValue != e.NewValue && e.NewValue != null) {
      var lv = (BaseListView)dependencyObject;
      var gridView = new GridView();
      lv.View = gridView;
      gridView.AllowsColumnReorder = true;
      var properties = lv.DataType.GetProperties();
      foreach (var pi in properties) {
        var binding = new Binding {Path = new PropertyPath(pi.Name), Mode = BindingMode.OneWay};
        var gridViewColumn = new GridViewColumn() {Header = pi.Name, DisplayMemberBinding = binding};
        gridView.Columns.Add(gridViewColumn);
      }
    }
  }

  public Type DataType { get; set; }
}

here is the xaml usage

<Grid>
  <local:BaseListView x:Name="listView" DataType="{x:Type DummyType}" ItemsSource="{Binding Mode=OneWay, Path=DummyTypeList}" />
</Grid>

thats it

here is my answer at stackoverflow

.NET DevCon 2011

2009 hat es mit der BASTA geklappt und dieses jahr ist es die .NET DevCon 2011 *freu*
2 tage geballtes wissen in sich aufsaugen und nicht mehr vergessen und abends ein kleines bierchen in der nürnberger altstadt, hach ist das schön :-)