Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 6th, 2012  |  syntax: None  |  size: 1.74 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to inject a view using datatemplate selector?
  2. public class BinaryProblem<T> {
  3.     public T Number1 { get; set; }
  4.     public T Number2 { get; set; }
  5. }
  6.        
  7. public class Fraction {
  8.     public int Numerator {get;set;}
  9.     public int Denominator {get;set;}
  10. }
  11.        
  12. <Grid>
  13.     <Grid.ColumnDefinitions>
  14.         <ColumnDefinition Width="Auto" />
  15.         <ColumnDefinition Width="Auto" />
  16.         <ColumnDefinition Width="Auto" />
  17.     </Grid.ColumnDefinitions>
  18.     <..Something.. Text="{Binding Number1}" Grid.Column="0" />
  19.     <TextBlock Grid.Column="1" Text="+" />
  20.     <..Something.. Text="{Binding Number2}"  Grid.Column="2" />
  21. </Grid>
  22.        
  23. <Grid>
  24.     <Grid.RowDefinitions>
  25.         <RowDefinition Height="Auto" />
  26.         <RowDefinition Height="Auto" />
  27.         <RowDefinition Height="Auto" />
  28.     </Grid.RowDefinitions>
  29.     <TextBlock Grid.Row="0" Text="{Binding Numerator}" />
  30.     <Rectangle Grid.Row="1" Fill="Black" Height="5" />
  31.     <TextBlock Grid.Row="2" Text="{Binding Denominator}" />
  32. </Grid>
  33.        
  34. <DataTemplate DataType="{x:Type local:Fraction}" >
  35.         <Grid>
  36.             <Grid.RowDefinitions>
  37.                 <RowDefinition Height="Auto" />
  38.                 <RowDefinition Height="Auto" />
  39.                 <RowDefinition Height="Auto" />
  40.             </Grid.RowDefinitions>
  41.             <TextBlock Grid.Row="0" Text="{Binding Numerator}" />
  42.             <Rectangle Grid.Row="1" Fill="Black" Height="5" />
  43.             <TextBlock Grid.Row="2" Text="{Binding Denominator}" />
  44.         </Grid>
  45.     </DataTemplate>
  46.  
  47.     <DataTemplate xmlns:sys="clr-namespace:System;assembly=mscorlib"
  48.                   DataType="{x:Type sys:Int32}" >
  49.         <TextBlock Background="Green" Text="{Binding}" />
  50.     </DataTemplate>
  51.        
  52. <ContentPresenter Grid.Column="0" Content="{Binding Number1}">