Beispiel #1
0
        protected override void OnSelectStyle(object item, TreeViewStyleContext styleContext)
        {
            var dataItem = item as TreeViewDataItem;

            if (dataItem != null)
            {
                var style = new TreeViewItemStyle();
                if (dataItem.IsLeaf == true)
                {
                    style.TextCellTextColor = Color.FromHex("#AAC7F6");
                    style.BackgroundColor   = Color.FromHex("#96CCFF");
                    style.BorderColor       = Color.FromHex("#0A3A82");
                    style.BorderLocation    = Telerik.XamarinForms.Common.Location.All;
                    style.BorderWidth       = 5;
                }
                else
                {
                    style.TextCellTextColor = Color.White;
                    style.BackgroundColor   = Color.FromHex("#356BFF");
                    style.BorderColor       = Color.FromHex("#96CCFF");
                    style.BorderLocation    = Telerik.XamarinForms.Common.Location.All;
                    style.BorderWidth       = 5;
                }
                styleContext.ItemStyle = style;
            }
        }
Beispiel #2
0
        public MainWindow()
        {
            SnapsToDevicePixels = true;
            Icon      = BitmapFrame.Create(Application.GetResourceStream(new Uri("/Icon.ico", UriKind.Relative)).Stream);
            MinWidth  = 600;
            MinHeight = 480;

            ConfigureWindowStateAndPosition();

            var apiList = new RestlessTreeView <ApiItemModel>();

            grid = new Grid();

            grid.AddColumn(300);
            grid.AddColumn(4);
            grid.AddColumn(1, GridUnitType.Star);

            grid.AddRow(1, GridUnitType.Star);
            grid.Add(apiList, 0, 0);
            grid.AddVerticalSplitter(200, 400);
            var apiListContextMenu = new ContextMenu();

            var addChildApiMenuItem           = apiListContextMenu.Add("Add Child _Api");
            var addChildApiCollectionMenuItem = apiListContextMenu.Add("Add Child Api _Collection");
            var apiDeleteMenuItem             = apiListContextMenu.Add("_Delete");

            apiList.ContextMenu = apiListContextMenu;

            var menu = new Menu();

            var fileMenu             = menu.Add("_File");
            var newApiMenuItem       = fileMenu.Add("New _Api");
            var newApiCollectionItem = fileMenu.Add("New Api _Collection");
            var exportAllMenuItem    = fileMenu.Add("_Export");
            var importMenuItem       = fileMenu.Add("_Import");

            var editMenu      = menu.Add("_Edit");
            var copyMenuItem  = editMenu.Add("_Copy");
            var pasteMenuItem = editMenu.Add("_Paste");

            var content = new DockPanel {
                LastChildFill = true
            };

            content.Add(menu, Dock.Top);
            content.Add(grid);

            Content = content;

            var apiPanel           = new ApiPanel();
            var apiCollectionPanel = new ApiCollectionPanel();

            var treeViewItemStyle = new TreeViewItemStyle();

            treeViewItemStyle.AddSetter(x => x.IsSelected, apiList.Bind(x => x.IsSelected));
            treeViewItemStyle.AddSetter(x => x.IsExpanded, apiList.Bind(x => x.IsExpanded));
            apiList.ItemContainerStyle = treeViewItemStyle;

            this.Bind(x => x.Title).To(this, (window, title) => window.Title = title ?? "");
            this.Bind(x => x.Items).To(apiList, x => x.Items, typeof(Item));
            this.Bind(x => x.DeleteSelectedItem).To(x => apiDeleteMenuItem.Command = x);

            var selectedItemChange        = this.Bind(x => x.SelectedItem).ObserveModelPropertyChange();
            var selectedItemNotNullChange = selectedItemChange.Where(x => x != null);

            selectedItemChange.Where(x => x == null).Subscribe(x => HideContent());
            selectedItemNotNullChange.OfType <ApiModel>().Subscribe(x =>
            {
                apiPanel.Model = x;
                ShowContent(apiPanel);
            });
            selectedItemNotNullChange.OfType <ApiCollectionModel>().Subscribe(x =>
            {
                apiCollectionPanel.Model = x;
                if (x != null)
                {
                    ShowContent(apiCollectionPanel);
                }
                else
                {
                    HideContent();
                }
            });

            this.Bind(x => x.SplitterPosition).Mate(grid.ColumnDefinitions[0], ColumnDefinition.WidthProperty);

            Action <ApiModel> onAddApi = apiModel =>
            {
                Model.SelectedItem = apiModel;
                ((ApiPanel)this.content).InitNew();
            };

            var addChildApi = this.Bind(x => x.AddChildApi);

            addChildApi.To(x => addChildApiMenuItem.Command = x);
            addChildApi.ObserveModelPropertyChange().SelectMany(x => x).Subscribe(onAddApi);

            var addChildApiCollection = this.Bind(x => x.AddChildApiCollection);

            addChildApiCollection.To(x => addChildApiCollectionMenuItem.Command = x);
            addChildApiCollection.ObserveModelPropertyChange().SelectMany(x => x).Subscribe(collectionModel =>
            {
                Model.SelectedItem = collectionModel;
            });

            var addApi = this.Bind(x => x.AddApi);

            addApi.To(x => newApiMenuItem.Command = x);
            addApi.ObserveModelPropertyChange().SelectMany(x => x).Subscribe(onAddApi);
            this.Bind(x => x.AddApiCollection).To(x => newApiCollectionItem.Command = x);

            this.Bind(x => x.Export).To(x => exportAllMenuItem.Command = x);
            this.Bind(x => x.Import).To(x => importMenuItem.Command    = x);
        }