|
<StackLayout Margin="5" Orientation="Vertical" BackgroundColor="White">
...
<sfTreeView:SfTreeView x:Name="treeView" NotificationSubscriptionMode="CollectionChange,PropertyChange"
ItemHeight="35"
Indentation="10"
IsAnimationEnabled="true"
ExpanderWidth="15"
CheckBoxMode="Recursive"
NodePopulationMode="Instant"
SelectionMode="Extended"
ItemTemplateContextType="Node"
CheckedItems="{Binding CheckedItems}"
ItemsSource="{Binding TreeData}"
AutoExpandMode="AllNodesExpanded">
...
</sfTreeView:SfTreeView>
<Grid HorizontalOptions="FillAndExpand" VerticalOptions="EndAndExpand">
...
<SfButtons:SfButton Grid.Row="0" Grid.Column="1"
Text="Add Leaf"
TextColor="Black"
HorizontalOptions="Center"
VerticalOptions="Center"
BackgroundColor="White"
CornerRadius="2"
BorderColor="#3246C7"
Command="{Binding ButtonAddLeafCommand}"
CommandParameter="{x:Reference treeView}">
</SfButtons:SfButton>
</Grid>
</StackLayout> |
|
public ICommand ButtonAddLeafCommand => new Command((object obj) => AddLeafButton(obj));
private void AddLeafButton(object obj)
{
try
{
var treeView = obj as Syncfusion.XForms.TreeView.SfTreeView;
if (TreeData.Count > 0 && (TreeData[0].Capacity > 0))
{
Tag bTag = new Tag();
bTag.Name = "Leaf_" + Lcount;
bTag.EPC = Guid.NewGuid().ToString();
var leaf = new LeafTree();
leaf.TagInfo = bTag;
ObservableCollection<LeafTree> auxL = TreeData[0].Leaves;
auxL.Add(leaf);
Device.BeginInvokeOnMainThread(async () =>
{
TreeData[0].Leaves = auxL;
TreeData[0].Capacity -= 1;
CheckedItems.Add(leaf);
await Task.Delay(500);
});
Lcount++;
treeView.BringIntoView(leaf, false, true);
}
else
{
string msg = String.Format("Max Capacity reach for:\n {0}\n Contact Supervisor.", TreeData[0].TagInfo.EPC);
}
}
catch (Exception ex)
{
}
} |