Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <TreeView Width="100">
- <TreeViewItem>
- <Grid>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="{Binding RelativeSource={RelativeSource AncestorType=TreeView}, Path=ActualWidth}"/>
- </Grid.ColumnDefinitions>
- <Grid.RowDefinitions>
- <RowDefinition/>
- <RowDefinition/>
- </Grid.RowDefinitions>
- <TextBlock Text="Lorem Ipsum" />
- <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."
- TextWrapping="Wrap" Grid.Row="1"/>
- </Grid>
- </TreeViewItem>
- </TreeView>
- width = actual_width_of_tree_view - relative_horizontal_offset_of_item
- public static Double GetProjectTitleWidth(DependencyObject obj)
- {
- return (Double)obj.GetValue(ProjectTitleWidthProperty);
- }
- public static void SetProjectTitleWidth(DependencyObject obj, Double value)
- {
- obj.SetValue(ProjectTitleWidthProperty, value);
- }
- public static readonly DependencyProperty ProjectTitleWidthProperty = DependencyProperty.RegisterAttached(
- "ProjectTitleWidth",
- typeof(Double),
- typeof(DatawareSearchView),
- new UIPropertyMetadata(0.0, ProjectTitleWidthChanged));
- private static void ProjectTitleWidthChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- var targetElement = d as FrameworkElement;
- if (targetElement != null)
- {
- var bindingExpr = targetElement.GetBindingExpression(ProjectTitleWidthProperty);
- var sourceElement = bindingExpr.DataItem as FrameworkElement;
- if (sourceElement != null)
- {
- // calculating relative offset
- var leftTop = targetElement.TranslatePoint(new Point(0.0, 0.0), sourceElement);
- // trying to find ScrollViewer
- var border = VisualTreeHelper.GetChild(sourceElement, 0);
- if (border != null)
- {
- var scrollViewer = VisualTreeHelper.GetChild(border, 0) as ScrollViewer;
- if (scrollViewer != null)
- {
- // setting width of target element
- targetElement.Width = scrollViewer.ViewportWidth - leftTop.X;
- }
- }
- }
- }
- }
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto"/>
- <RowDefinition Height="*" />
- </Grid.RowDefinitions>
- <TextBlock Text="{Binding Model.Code}" FontWeight="DemiBold" />
- <TextBlock Text="{Binding Model.Title}" TextWrapping="Wrap" Foreground="Gray" x:Name="tbTitle" Grid.Row="1"
- localviews:DatawareSearchView.ProjectTitleWidth="{Binding RelativeSource={RelativeSource AncestorType=TreeView}, Path=ActualWidth}"/>
- </Grid>
- <TextBlock Text="{Binding Model.Title}" Width="{Binding ActualWidth,
- ElementName=tvDatawareObjects}" TextWrapping="Wrap" Foreground="Gray" Grid.Row="1"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement