Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. <TreeView Width="100">
  2. <TreeViewItem>
  3. <Grid>
  4. <Grid.ColumnDefinitions>
  5. <ColumnDefinition Width="{Binding RelativeSource={RelativeSource AncestorType=TreeView}, Path=ActualWidth}"/>
  6. </Grid.ColumnDefinitions>
  7. <Grid.RowDefinitions>
  8. <RowDefinition/>
  9. <RowDefinition/>
  10. </Grid.RowDefinitions>
  11. <TextBlock Text="Lorem Ipsum" />
  12. <TextBlock Text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."
  13. TextWrapping="Wrap" Grid.Row="1"/>
  14. </Grid>
  15. </TreeViewItem>
  16. </TreeView>
  17.  
  18. width = actual_width_of_tree_view - relative_horizontal_offset_of_item
  19.  
  20. public static Double GetProjectTitleWidth(DependencyObject obj)
  21. {
  22. return (Double)obj.GetValue(ProjectTitleWidthProperty);
  23. }
  24.  
  25. public static void SetProjectTitleWidth(DependencyObject obj, Double value)
  26. {
  27. obj.SetValue(ProjectTitleWidthProperty, value);
  28. }
  29.  
  30. public static readonly DependencyProperty ProjectTitleWidthProperty = DependencyProperty.RegisterAttached(
  31. "ProjectTitleWidth",
  32. typeof(Double),
  33. typeof(DatawareSearchView),
  34. new UIPropertyMetadata(0.0, ProjectTitleWidthChanged));
  35.  
  36. private static void ProjectTitleWidthChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  37. {
  38. var targetElement = d as FrameworkElement;
  39. if (targetElement != null)
  40. {
  41. var bindingExpr = targetElement.GetBindingExpression(ProjectTitleWidthProperty);
  42. var sourceElement = bindingExpr.DataItem as FrameworkElement;
  43. if (sourceElement != null)
  44. {
  45. // calculating relative offset
  46. var leftTop = targetElement.TranslatePoint(new Point(0.0, 0.0), sourceElement);
  47.  
  48. // trying to find ScrollViewer
  49. var border = VisualTreeHelper.GetChild(sourceElement, 0);
  50. if (border != null)
  51. {
  52. var scrollViewer = VisualTreeHelper.GetChild(border, 0) as ScrollViewer;
  53. if (scrollViewer != null)
  54. {
  55. // setting width of target element
  56. targetElement.Width = scrollViewer.ViewportWidth - leftTop.X;
  57. }
  58. }
  59. }
  60. }
  61. }
  62.  
  63. <Grid>
  64. <Grid.RowDefinitions>
  65. <RowDefinition Height="Auto"/>
  66. <RowDefinition Height="*" />
  67. </Grid.RowDefinitions>
  68.  
  69. <TextBlock Text="{Binding Model.Code}" FontWeight="DemiBold" />
  70. <TextBlock Text="{Binding Model.Title}" TextWrapping="Wrap" Foreground="Gray" x:Name="tbTitle" Grid.Row="1"
  71. localviews:DatawareSearchView.ProjectTitleWidth="{Binding RelativeSource={RelativeSource AncestorType=TreeView}, Path=ActualWidth}"/>
  72. </Grid>
  73.  
  74. <TextBlock Text="{Binding Model.Title}" Width="{Binding ActualWidth,
  75. ElementName=tvDatawareObjects}" TextWrapping="Wrap" Foreground="Gray" Grid.Row="1"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement