如何以编程方式更新 SyncFusion UWP 图的节点和连接器?
How do you update the nodes and connectors of a SyncFusion UWP Diagram programmatically?
我正在评估 SyncFusion SfDiagram,但无法找到一种方法来更新 UWP 中 C# 的节点和连接器?我正在根据 Getting Started 文档中给出的示例进行测试,并将 EmpId 修改为字符串。结果是添加了新节点,但仍显示原始节点。我希望只看到我在 C# 代码中添加的两个节点。
我发现他们的文档有点混乱。我尝试了以下方法:
XAML
<local:Employees x:Name="EmployeesCollection" x:Key="Employees">
<local:Employee Name="Elizabeth" EmpId="1" ParentId="" Designation="CEO"/>
<local:Employee Name="Christina" EmpId="2" ParentId="1" Designation="Manager"/>
</local:Employees>
C#
EmployeesCollection.Clear();
employee e = new Employee();
e.Name = t.Designation = e.EmpId = "10";
e.ParentId = "";
EmployeesCollection.Add(e);
employee e = new Employee();
e.Name = t.Designation = e.EmpId = "11";
e.ParentId = "10";
EmployeesCollection.Add(e);
diagram.UpdateLayout();
感谢 Keyur Patel 的建议。我发现我必须在更新之前清空 DataSourceSettings(奇怪)。我将 x:Name 添加到他们示例中的 DataSourceSettings(将其命名为 DiagramDataSourceSettings)。这是我添加的内容以清除原始节点并使用我的新节点进行更新:
diagram.DataSourceSettings = null;
diagram.DataSourceSettings = DiagramDataSourceSettings;
diagram.UpdateLayout();
现在的问题是,当它更新时,它会将新节点放在右上角(稍微看不见)。
请在 运行 时按如下方式更新数据源设置,
Employees employees = new Employees();
DataSourceSettings settings = new DataSourceSettings();
settings.ParentId = "ParentId";
settings.Id = "EmpId";
employees.Add(new Employee() { EmpId = 1, ParentId = "", Name = "Charly", Designation = "Manager" });
employees.Add(new Employee() { EmpId = 2, ParentId = "1", Name = "Ronald", Designation = "TeamLead" });
settings.DataSource = employees;
sfdiagram.DataSourceSettings = settings;
对 LayoutManager 的 RefreshFrequency 属性 支持。 RefreshFrequency 属性 用于在节点或连接器集合发生更改时更新布局。提供的代码示例来表示这一点。请参考下面的代码示例。
代码示例:
sfdiagram.LayoutManager.RefreshFrequency = RefreshFrequency.ArrangeParsing;
Here, sfdiagram is instance of SfDiagram
更多信息,请参考下面的知识库link。
https://www.syncfusion.com/kb/6258/how-to-update-layout-automatically-when-collection-is-changed
建议二:
Layout 的UpdateLayout 方法支持。它用于排列节点 Position.The 提供了代码示例来表示这一点。
代码示例:
//Diagram Loaded Event
sfdiagram.Loaded += MainWindow_Loaded;
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
sfdiagram.LayoutManager.Layout.UpdateLayout();
}
Here, sfdiagram is instance of SfDiagram.
有关 UpdateLayout 的更多信息,请参阅下面的文档 link。
文档 link:https://help.syncfusion.com/wpf/sfdiagram/automatic-layouts#updating-the-layout
此致,
Keerthivasan R.
我也在评估SF图。
我正在尝试从 ViewModel 的角度来做所有事情。我将图表的 DataSourceSetting 绑定到 DataSourceSettings 类型的 VM 属性。
在 ViewModel 中,我将 DataSourceSettings 数据源 属性 更改为新集合。
Activities = new ObservableCollection<Activity>(App.AppState.BPAnalysis.IDEFOActivities[0].Activities.ToList());
DS.DataSource = Activities;
OnDiagramUpdated(EventArgs.Empty);
现在从 ViewModel 的角度来看丑陋的部分。我的 Viewmodel 引发了一个 "OnDiagramUpdated" 事件,我在 te codebhind 中处理它是这样的:
public sealed partial class Diagramer : UserControl
{
ViewModels.DiagramVM vm = null;
public Diagramer()
{
this.InitializeComponent();
vm = new ViewModels.DiagramVM();
this.DataContext = vm;
vm.DiagramUpdated += (s, e) =>
{
DG1.LayoutManager.RefreshFrequency = RefreshFrequency.ArrangeParsing;
};
}
}
RefreshFrequency 行导致重绘。也许这会有所帮助。
我正在评估 SyncFusion SfDiagram,但无法找到一种方法来更新 UWP 中 C# 的节点和连接器?我正在根据 Getting Started 文档中给出的示例进行测试,并将 EmpId 修改为字符串。结果是添加了新节点,但仍显示原始节点。我希望只看到我在 C# 代码中添加的两个节点。
我发现他们的文档有点混乱。我尝试了以下方法:
XAML
<local:Employees x:Name="EmployeesCollection" x:Key="Employees">
<local:Employee Name="Elizabeth" EmpId="1" ParentId="" Designation="CEO"/>
<local:Employee Name="Christina" EmpId="2" ParentId="1" Designation="Manager"/>
</local:Employees>
C#
EmployeesCollection.Clear();
employee e = new Employee();
e.Name = t.Designation = e.EmpId = "10";
e.ParentId = "";
EmployeesCollection.Add(e);
employee e = new Employee();
e.Name = t.Designation = e.EmpId = "11";
e.ParentId = "10";
EmployeesCollection.Add(e);
diagram.UpdateLayout();
感谢 Keyur Patel 的建议。我发现我必须在更新之前清空 DataSourceSettings(奇怪)。我将 x:Name 添加到他们示例中的 DataSourceSettings(将其命名为 DiagramDataSourceSettings)。这是我添加的内容以清除原始节点并使用我的新节点进行更新:
diagram.DataSourceSettings = null;
diagram.DataSourceSettings = DiagramDataSourceSettings;
diagram.UpdateLayout();
现在的问题是,当它更新时,它会将新节点放在右上角(稍微看不见)。
请在 运行 时按如下方式更新数据源设置,
Employees employees = new Employees();
DataSourceSettings settings = new DataSourceSettings();
settings.ParentId = "ParentId";
settings.Id = "EmpId";
employees.Add(new Employee() { EmpId = 1, ParentId = "", Name = "Charly", Designation = "Manager" });
employees.Add(new Employee() { EmpId = 2, ParentId = "1", Name = "Ronald", Designation = "TeamLead" });
settings.DataSource = employees;
sfdiagram.DataSourceSettings = settings;
对 LayoutManager 的 RefreshFrequency 属性 支持。 RefreshFrequency 属性 用于在节点或连接器集合发生更改时更新布局。提供的代码示例来表示这一点。请参考下面的代码示例。
代码示例:
sfdiagram.LayoutManager.RefreshFrequency = RefreshFrequency.ArrangeParsing;
Here, sfdiagram is instance of SfDiagram
更多信息,请参考下面的知识库link。
https://www.syncfusion.com/kb/6258/how-to-update-layout-automatically-when-collection-is-changed
建议二: Layout 的UpdateLayout 方法支持。它用于排列节点 Position.The 提供了代码示例来表示这一点。
代码示例:
//Diagram Loaded Event
sfdiagram.Loaded += MainWindow_Loaded;
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
sfdiagram.LayoutManager.Layout.UpdateLayout();
}
Here, sfdiagram is instance of SfDiagram.
有关 UpdateLayout 的更多信息,请参阅下面的文档 link。
文档 link:https://help.syncfusion.com/wpf/sfdiagram/automatic-layouts#updating-the-layout
此致,
Keerthivasan R.
我也在评估SF图。
我正在尝试从 ViewModel 的角度来做所有事情。我将图表的 DataSourceSetting 绑定到 DataSourceSettings 类型的 VM 属性。 在 ViewModel 中,我将 DataSourceSettings 数据源 属性 更改为新集合。
Activities = new ObservableCollection<Activity>(App.AppState.BPAnalysis.IDEFOActivities[0].Activities.ToList());
DS.DataSource = Activities;
OnDiagramUpdated(EventArgs.Empty);
现在从 ViewModel 的角度来看丑陋的部分。我的 Viewmodel 引发了一个 "OnDiagramUpdated" 事件,我在 te codebhind 中处理它是这样的:
public sealed partial class Diagramer : UserControl
{
ViewModels.DiagramVM vm = null;
public Diagramer()
{
this.InitializeComponent();
vm = new ViewModels.DiagramVM();
this.DataContext = vm;
vm.DiagramUpdated += (s, e) =>
{
DG1.LayoutManager.RefreshFrequency = RefreshFrequency.ArrangeParsing;
};
}
}
RefreshFrequency 行导致重绘。也许这会有所帮助。