2024年4月3日发(作者:)
<>
>
<>
>
<>
>
<>
>
using System;
using c;
using Model;
using ;
using ;
using ;
using s;
using ls;
using ;
using nts;
using ;
using ;
using g;
using tion;
using ;
namespace TreeViewStyleDemo
{
///
/// 的交互逻辑
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
for (int i = 0; i < 3; i++)
{
var item = new ItemViewModel();
= "Item" + i;
en = new ObservableCollection
for (int j = 0; j < 3; j++)
{
var sub_item = new ItemViewModel(){ Name = "SubItem" + j};
sub_en = new ObservableCollection
for (int k = 0; k < 3; k++)
{
sub_(new ItemViewModel() { Name = "SubsubItem" + k });
}
(sub_item);
}
(item);
}
ource = items;
}
ObservableCollection
private void Button_Click(object sender, RoutedEventArgs e)
{
items[0].(new ItemViewModel() { Name = "Added" });
}
}
public class ItemViewModel
{
public string Name { get; set; }
public IList
}
public class CustomPanel : StackPanel
{
protected override Size ArrangeOverride(Size arrangeSize)
{
return eOverride(arrangeSize);
}
protected override Size MeasureOverride(Size constraint)
{
return eOverride(constraint);
}
protected override void OnRender(DrawingContext dc)
{
er(dc);
if ( > 0)
{
TreeViewItem child;
Point point;
Pen pen = new Pen(LineBrush, LineThiness);
Point startPoint = new Point(Offset,0), endPoint = new Point(Offset,0);
for (int i = 0; i < - 1; i++)
{
child = Children[i] as TreeViewItem;
point = atePoint(new Point(), this);
startPoint.Y = point.Y;
endPoint.Y = point.Y + ;
ne(pen, startPoint, endPoint);
}
child = Children[ - 1] as TreeViewItem;
point = atePoint(new Point(), this);
startPoint.Y = point.Y;
if (!nded || == null || < 1)
endPoint.Y = point.Y + / 2;
else
endPoint.Y = point.Y + / / 2;
ne(pen, startPoint, endPoint);
}
}
public Brush LineBrush
{
get { return (Brush)GetValue(LineBrushProperty); }
set { SetValue(LineBrushProperty, value); }
}
public static readonly DependencyProperty LineBrushProperty =
er("LineBrush", typeof(Brush), typeof(CustomPanel), new PropertyMetadata(null));
public double LineThiness
{
get { return (double)GetValue(LineThinessProperty); }
set { SetValue(LineThinessProperty, value); }
}
public static readonly DependencyProperty LineThinessProperty = er("LineThiness", typeof(double), typeof(CustomPanel), new PropertyMetadata(0d, new PropertyChangedCallback((o,e)=>{(o as Panel).Invalidate


发布评论