本帖最后由 dddsssssqq 于 2024-10-14 20:14 编辑
将IsExpand 修改为bool类型,
用下面的函数构造一个数据
private CloudRulePathModel CreateData(int level, string name) {
var model = new CloudRulePathModel {
Name = name,
IsExpand = level % 2 == 0
};
for (var i = 0; i < level; i++) {
model.ChildRule.Add(CreateData(--level, $"child node {i}"));
}
return model;
}
将数据作为C1OrgChart的Header
_orgChart.Header = CreateData(5, "root");
xaml代码如下:
<c1:C1OrgChart
x:Name="_orgChart"
Orientation="Horizontal"
IsCollapsed="{Binding IsExpand}"
ChildSpacing="1,1"
ConnectorStroke="Black"
ConnectorThickness="{Binding Path=ChildRule.Count}">
<c1:C1OrgChart.ItemTemplate>
<DataTemplate>
<Border
Background="#ff88bde6" BorderBrush="Black"
BorderThickness="1 1 2 2" CornerRadius="6"
Margin="20" MaxWidth="200">
<StackPanel Orientation="Vertical">
<Border CornerRadius="6 6 0 0" Background="Black">
<TextBlock Text="{Binding Name}" FontWeight="Bold" FontSize="14" Foreground="#ff88bde6" Padding="4 0 0 0"/>
</Border>
<CheckBox
Margin="4 0"
IsChecked="{Binding IsCollapsed, Mode=TwoWay, RelativeSource={RelativeSource AncestorType=c1:C1OrgChart}}"/>
</StackPanel>
</Border>
</DataTemplate>
</c1:C1OrgChart.ItemTemplate>
</c1:C1OrgChart>
我想将对应节点的折叠和IsExpand属性绑定,实际显示结果不没有折叠
IsCollapsed和ConnectorThickness的绑定是一致的。IsCollapsed没有绑定成功
|