code_junkie

XAML Template Binding Horizontally

Nov 13th, 2011
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. int tbIndex = 0;
  2. for (int i = 1; i < 5; i++) {
  3. StackPanel pan = new StackPanel();
  4. pan.Orientation = Orientation.Horizontal;
  5. pan.Margin = new Thickness(3);
  6. pan.Name = "RowPanel" + i;
  7. for (int j = 0; j < 3; j++) {
  8. CheckBox cb = new CheckBox();
  9. TextBlock block = new TextBlock();
  10. block.Width = 75;
  11. block.Text = "Item " + (++tbIndex).ToString();
  12. pan.Children.Add( cb );
  13. pan.Children.Add( block );
  14. }
  15. ContentPanel.Children.Add( pan );
  16. }
  17.  
  18. <ItemsControl ItemsSource="{Binding YourListOfItems}">
  19. <ItemsControl.ItemTemplate>
  20. <DataTemplate>
  21. <StackPanel Orientation="Horizontal">
  22. <CheckBox IsChecked="{Binding YourIsChecked}"/>
  23. <TextBlock Text="{Binding YourText}"/>
  24. </StackPanel>
  25. </DataTemplate>
  26. </ItemsControl.ItemTemplate>
  27. </ItemsControl>
  28.  
  29. <ItemsControl x:Name="myItems" Width="300">
  30. <ItemsControl.ItemsPanel>
  31. <ItemsPanelTemplate>
  32. <controls:WrapPanel x:Name="itemsWrapPanel" Margin="0" Orientation="Horizontal" />
  33. </ItemsPanelTemplate>
  34. </ItemsControl.ItemsPanel>
  35. <ItemsControl.ItemTemplate>
  36. <DataTemplate>
  37. <StackPanel Orientation="Horizontal" Width="100">
  38. <CheckBox IsChecked="{Binding MyCheckedProperty, Mode=TwoWay}" x:Name="IsSelectedCheckBox" Height="25"></CheckBox>
  39. <TextBlock Height="12" Text="{Binding MyTextProperty}" Margin="0" />
  40. </StackPanel>
  41. </DataTemplate>
  42. </ItemsControl.ItemTemplate>
  43. </ItemsControl>
Add Comment
Please, Sign In to add comment