Skip to content

Instantly share code, notes, and snippets.

@grokys
Last active May 18, 2020 16:11
Show Gist options
  • Save grokys/5c57ed0716ba768c7fa8a244a32b6fe0 to your computer and use it in GitHub Desktop.
Save grokys/5c57ed0716ba768c7fa8a244a32b6fe0 to your computer and use it in GitHub Desktop.

Simplest Hello World

class Item
{
  public string Header { get; }
  public ObservableCollection<Items> Children { get; }
  public override string ToString() => Header;
}
<LeanPrawn Items="{Binding Items}" ChildSelector="{Binding Children}"/>

Longer version

  • DataTemplate instead of relying on ToString
  • Include LeanPrawnSource instead of specifying ChildSelector on control itself
    • Specifying it on control is horthand for creating a LeanPrawnSource and setting its ChildSelector
  • Content property is Columns
class Item
{
  public string Header { get; }
  public ObservableCollection<Items> Children { get; }
}
<LeanPrawn Items="{Binding Items}">
  <LeanPrawn.Source>
    <LeanPrawnSource ChildSelector="{Binding Children}"/>
  </LeanPrawn.Source>
  <LeanPrawnColumn>
    <DataTemplate>
	  <TextBlock Text="{Binding Header}/>
    </DataTemplate>
  </LeanPrawnColumn>
</LeanPrawn>

Tree with Badge

class Item
{
  public string Header { get; }
  public int Unread { get; }
  public ObservableCollection<Items> Children { get; }
}
<LeanPrawn Items="{Binding Items}" ChildSelector="{Binding Children}">
  
  <LeanPrawnColumn>
    <DataTemplate>
      <TextBlock Text="{Binding Header}/>
    </DataTemplate>
  </LeanPrawnColumn>
  
  <LeanPrawnColumn Width="Auto">
    <DataTemplate>
      <Border CornerRadius="4" Background="Red" IsVisible="{Binding !!Unread}">
	<TextBlock Text="{Binding Unread}/>
      </Border>
    </DataTemplate>
  </LeanPrawnColumn>
  
</LeanPrawn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment