![]() ![]() Sender.SetValue(IsLastOneProperty, isLastOne) Public static void SetIsLastOne(DependencyObject sender, bool isLastOne) Return ( bool)sender.GetValue(IsLastOneProperty) Public static bool GetIsLastOne(DependencyObject sender) Public static DependencyProperty IsLastOneProperty =ĭependencyProperty.RegisterAttached( " IsLastOne", typeof( bool), typeof(TVIExtender)) Public static DependencyProperty ItemExtenderProperty =ĭependencyProperty.RegisterAttached( " ItemExtender", typeof(TVIExtender), typeof(TVIExtender)) Item.SetValue(ItemExtenderProperty, DependencyProperty.UnsetValue) TVIExtender extender = (TVIExtender)item.ReadLocalValue(ItemExtenderProperty) If (item.ReadLocalValue(ItemExtenderProperty) != DependencyProperty.UnsetValue) Item.SetValue(ItemExtenderProperty, extender) TVIExtender extender = new TVIExtender(item) If (item.ReadLocalValue(ItemExtenderProperty) = DependencyProperty.UnsetValue) TreeViewItem item = sender as TreeViewItem Private static void OnChangedUseExtender(DependencyObject sender, DependencyPropert圜hangedEventArgs e) Sender.SetValue(UseExtenderProperty, useExtender) Public static void SetUseExtender(DependencyObject sender, bool useExtender) Return ( bool)sender.GetValue(UseExtenderProperty) Public static bool GetUseExtender(DependencyObject sender) New PropertyMetadata( false, new Propert圜hangedCallback(OnChangedUseExtender))) Public static DependencyProperty UseExtenderProperty =ĭependencyProperty.RegisterAttached( " UseExtender", typeof( bool), typeof(TVIExtender), ![]() You can download the demo from this link: When the TreeView.ActualWidth and TreeView.ActualHeigth update, the Rectangle.Height will update also. Public object ConvertBack(object value, Type targetTypes, object parameter, CultureInfo culture) Rectangle.VerticalAlignment = VerticalAlignment.Stretch Rectangle.VerticalAlignment = VerticalAlignment.Top Rectangle rectangle = values as Rectangle ItemsControl ic = ItemsControl.ItemsControlFromItemContainer(item) īool isLastOne = ic.ItemContainerGenerator.IndexFromContainer(item) = ic.Items.Count - 1 TreeViewItem item = values as TreeViewItem Public object Convert(object values, Type targetType, object parameter, CultureInfo culture) The LineConver is IMultiValueConverter,and the code is below:Ĭlass TreeViewLineConverter : IMultiValueConverter I have a simple soulution to solve your problem,the code is below: Added some explanation and pointed out the issue.Adjusted better position/size of connecting lines.Changed triangle toggle button to plus-minus button.My rewrite code is almost the same as that, the differences are: Social MSDN: Show TreeView nodes connected with dotted lines.This is the code I referenced before I wrote my own: If you know how to fix this issue, please post it as a comment. This problem also occurs when you change font size of treeview item. There is a problem with vertical line when you add a new TreeViewItem into TreeView, then the connecting line is not updated: The full trigger can be found in the attached file. You can add more trigger to control behavior of TreeView if you want. The TreeView will have WinForms style now. This class will change the connecting lines if the item is the last in the list: Then, you need put the class TreeViewLineConverter to your namespace. Then, you need to draw vertical and horizontal connecting lines between nodes: You need to redesign TreeViewItem control. In the above code, you can see a trigger, it will make the vertical line inside toggle button hide if item is expanded, or show if its children collapsed. When TreeViewItem is expanded, the vertical line will hide: Hope this will help many people! Table of ContentsĪll you need is an XAML file and a code behind.įirst, you need draw Toggle Button: From Triangle button to Plus-Minus button: draw a rectangle with dark border, then draw two lines, one vertical line and one horizontal line. Now, I myself designed a TreeView with style as WinForms. ![]() I have searched on the internet and have some examples, but they were not designed well enough. WPF default TreeView is very good, but many people still want it to have lines join each of its child elements, like Windows Forms TreeView, including me. In case you load all TreeViewItems at one time to TreeView control (that means you don't add or remove item after showing it), my article solution may be more lightweight. Note: Kenneth Haugland has posted a better solution on this article: Examples of Attached Behaviors in WPF. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |