Example #1
0
 public Keyword(DataModel.Keyword data) {
   Data = data;
   Id = data.Id;
   Index = data.Idx;
   IconName = "appbar_tag";
   FullPath = data.Name;
   Title = data.Name.Contains("/")
     ? data.Name.Substring(data.Name.LastIndexOf("/", StringComparison.OrdinalIgnoreCase) + 1)
     : data.Name;
 }
Example #2
0
    public Keyword CreateKeyword(BaseTreeViewItem root, string name) {
      if (root == null) return null;

      var parent = root as Keyword;
      var dmKeyword = new DataModel.Keyword {
        Id = ACore.Db.GetNextIdFor<DataModel.Keyword>(),
        Name = parent == null ? name : $"{parent.FullPath}/{name}"
      };
      ACore.Db.Insert(dmKeyword);

      var vmKeyword = new Keyword(dmKeyword) {Parent = root};
      AllKeywords.Add(vmKeyword);

      try {
        Keyword keyword = root.Items.Cast<Keyword>().FirstOrDefault(k => k.Index == 0 && string.Compare(k.Title, name, StringComparison.OrdinalIgnoreCase) >= 0);
        root.Items.Insert(keyword == null ? 0 : root.Items.IndexOf(keyword), vmKeyword);
      }
      catch (Exception ex) {
        //BUG This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread.
      }

      return vmKeyword;
    }