Exemplo n.º 1
0
        private MenuItem MenuItemFromNavigationPaneItem(NavigationPaneItem item, bool isHiddenItem)
        {
            MenuItem menuItem = new MenuItem();

            menuItem.IsCheckable = true;

            Binding b = new Binding();

            b.Source = item;
            if (isHiddenItem)
            {
                b.Path = new PropertyPath(Selector.IsSelectedProperty);
            }
            else
            {
                b.Path      = new PropertyPath(NavigationPane.IsItemExcludedProperty);
                b.Converter = new BooleanNegateConverter();
            }
            b.Mode = BindingMode.TwoWay;

            menuItem.SetBinding(MenuItem.IsCheckedProperty, b);

            if (item.ImageSmall != null)
            {
                Image image = new Image();
                image.Width   = 16;
                image.Height  = 16;
                image.Source  = item.ImageSmall;
                menuItem.Icon = image;
            }
            menuItem.Header = XamlHelper.CloneUsingXaml(item.Header, true);

            return(menuItem);
        }
Exemplo n.º 2
0
        private Canvas FormationCanvas()
        {
            var editFormationControlTemplate = (ControlTemplate)Resources["EditFormationTemplate"];
            var formationItemsControl        = (ItemsControl)editFormationControlTemplate.FindName("FormationItemsControl", FormationContentControl);

            return(XamlHelper.FindChild <Canvas>(this, "FormationCanvas"));
        }
Exemplo n.º 3
0
        private static void OnRunStreamChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (!(d is RichTextBox target))
            {
                return;
            }

            void OnMessage(object sender, Run run)
            {
                var para = GetOrCreateParagraph(target);

                para.Inlines.Add(XamlHelper.XamlClone(run));
                target.ScrollToEnd();
            }

            if (e.OldValue != null)
            {
                var coll = (RunStream)e.OldValue;
                coll.OnMessage -= OnMessage;
            }

            if (e.NewValue != null)
            {
                var coll = (RunStream)e.NewValue;
                coll.OnMessage += OnMessage;
            }
        }
Exemplo n.º 4
0
 public void LoadTheme(Theme theme)
 {
     try
     {
         if (theme == null)
         {
             theme = DefaultTheme;
         }
         if (theme.Path.StartsWith("/Cleverdock;component/"))
         {
             LoadComponentTheme(theme.Path);
         }
         else
         {
             var xaml = XamlHelper.LoadXaml(theme.Path);
             LoadResourceDictionary(xaml);
         }
         SettingsManager.Settings.Theme = theme;
         if (ThemeChanged != null)
         {
             ThemeChanged(this, new ThemeEventArgs(theme));
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Theme \"" + theme.Name + "\" failed to load. \n" + ex.Message);
         LoadTheme(DefaultTheme);
     }
 }
Exemplo n.º 5
0
        public PageHeader()
        {
            this.InitializeComponent();
            PrimaryCommands   = HeaderCommandBar.PrimaryCommands;
            SecondaryCommands = HeaderCommandBar.SecondaryCommands;
            this.Background   = HeaderCommandBar.Background;
            HeaderCommandBar.SetBinding(CommandBar.BackgroundProperty, new Binding
            {
                Path   = new PropertyPath(nameof(Background)),
                Source = this
            });

            // TODO
            Action updateEllipse = () =>
            {
                var controls = XamlHelper.AllChildren <Control>(HeaderCommandBar);
                var buttons  = controls.OfType <Button>();
                var button   = buttons.FirstOrDefault(x => x.Name.Equals("MoreButton"));
                if (button != null)
                {
                    var count = HeaderCommandBar.PrimaryCommands.OfType <Control>().Count(x => x.Visibility.Equals(Visibility.Visible));
                    count            += HeaderCommandBar.SecondaryCommands.OfType <Control>().Count(x => x.Visibility.Equals(Visibility.Visible));
                    button.Visibility = (count > 0) ? Visibility.Visible : Visibility.Collapsed;
                }
            };

            PrimaryCommands.VectorChanged += (s, e) => updateEllipse();
            HeaderCommandBar.Loaded       += (s, e) => updateEllipse();
        }
Exemplo n.º 6
0
        public ThemeSettingsViewModel LoadTheme(ThemeModel theme)
        {
            ThemeSettingsViewModel result = null;

            try
            {
                if (theme == null)
                {
                    theme = DefaultTheme;
                }
                if (theme.Path.StartsWith("/Cleverdock;component/"))
                {
                    LoadComponentTheme(theme.Path);
                }
                else
                {
                    var xamlPath = Path.Combine(theme.Path, "style.xaml");
                    var xaml     = XamlHelper.LoadXaml(xamlPath);
                    LoadResourceDictionary(xaml);
                    var settingsPath = Path.Combine(theme.Path, "theme.json");
                    result = GetSettings(settingsPath);
                }
                VMLocator.Main.Theme = theme;
                if (ThemeChanged != null)
                {
                    ThemeChanged(this, new ThemeEventArgs(theme));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Theme \"" + theme.Name + "\" failed to load. \n" + ex.Message);
                LoadTheme(DefaultTheme);
            }
            return(result);
        }
 private bool CheckIsClickCheckBox(object obj)
 {
     if (XamlHelper.FindUpVisualTree <CheckBox>(obj as DependencyObject) != null)
     {
         return(true);
     }
     return(false);
 }
        Activity GetRootRuntimeWorkflowElement()
        {
            Activity root = XamlHelper.GetActivity(_designer.Text);

            WorkflowInspectionServices.CacheMetadata(root);

            IEnumerator <Activity> enumerator1 = WorkflowInspectionServices.GetActivities(root).GetEnumerator();

            //Get the first child of the x:class
            enumerator1.MoveNext();
            root = enumerator1.Current;
            return(root);
        }
Exemplo n.º 9
0
 private void ResetItems()
 {
     Items.Clear();
     for (int j = 0; j < navigationPane.Items.Count; j++)
     {
         NavigationPaneItem item = navigationPane.Items[j] is NavigationPaneItem ? navigationPane.Items[j] as NavigationPaneItem:
                                   navigationPane.ItemContainerGenerator.ContainerFromIndex(j) as NavigationPaneItem;
         if (item != null)
         {
             Items.Add(new NavigationPaneOptionsData(item, XamlHelper.CloneUsingXaml(item.Header, true), !NavigationPane.GetIsItemExcluded(item)));
         }
     }
 }
Exemplo n.º 10
0
        private void LoadBoard()
        {
            this.Dispatcher.Invoke(new Action(() =>
            {
                XamlHelper.HideWithAnimation(LevelsContainer);
                XamlHelper.HideWithAnimation(CloseImage);
                XamlHelper.HideWithAnimation(AboutImage);

                XamlHelper.ShowWithAnimation(BoardContainer);
                XamlHelper.ShowWithAnimation(BackImage);
                XamlHelper.ShowWithAnimation(RefreshImage);
            }));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Applies the binding.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="property">The property.</param>
        internal void ApplyBinding(DependencyObject target, DependencyProperty property)
        {
            BindingBase binding = this.Binding;

            if (binding != null)
            {
                BindingBase clone = (BindingBase)XamlHelper.Clone(binding);
                clone.StringFormat = "{0:" + this.FormatString + "}";
                BindingOperations.SetBinding(target, property, clone);
            }
            else
            {
                BindingOperations.ClearBinding(target, property);
            }
        }
Exemplo n.º 12
0
        private static void OnBindedDocumentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (!(d is RichTextBox target))
            {
                return;
            }

            FlowDocument doc = e.NewValue as FlowDocument;

            if (doc == null)
            {
                target.Document = new FlowDocument();
                return;
            }

            target.Document = XamlHelper.XamlClone(doc);
        }
        public static void ScrollIntoViewSmoothly(this ListViewBase listViewBase, object item, ScrollIntoViewAlignment alignment)
        {
            if (listViewBase == null)
            {
                throw new ArgumentException(nameof(ListViewBase));
            }

            // GetFirstDescendantOfType 是 WinRTXamlToolkit 中的扩展方法,
            // 寻找该控件在可视树上第一个符合类型的子元素。
            ScrollViewer scrollViewer = XamlHelper.FindChildOfType <ScrollViewer>(listViewBase);

            // 由于 ScrollViewer 肯定有,因此不做 null 检查判断了。

            // 记录初始位置,用于 ScrollIntoView 检测目标位置后复原。
            double originHorizontalOffset = scrollViewer.HorizontalOffset;
            double originVerticalOffset   = scrollViewer.VerticalOffset;

            EventHandler <object> layoutUpdatedHandler = null;

            layoutUpdatedHandler = delegate
            {
                listViewBase.LayoutUpdated -= layoutUpdatedHandler;

                // 获取目标位置。
                double targetHorizontalOffset = scrollViewer.HorizontalOffset;
                double targetVerticalOffset   = scrollViewer.VerticalOffset;

                EventHandler <ScrollViewerViewChangedEventArgs> scrollHandler = null;
                scrollHandler = delegate
                {
                    scrollViewer.ViewChanged -= scrollHandler;

                    // 最终目的,带平滑滚动效果滚动到 item。
                    scrollViewer.ChangeView(targetHorizontalOffset, targetVerticalOffset, null);
                };
                scrollViewer.ViewChanged += scrollHandler;

                // 复原位置,且不需要使用动画效果。
                scrollViewer.ChangeView(originHorizontalOffset, originVerticalOffset, null, true);
            };
            listViewBase.LayoutUpdated += layoutUpdatedHandler;

            // 跑腿。
            listViewBase.ScrollIntoView(item, alignment);
        }
Exemplo n.º 14
0
        private void LoadMenu()
        {
            this.Dispatcher.Invoke(new Action(() =>
            {
                LevelPlaceholder.Content = new LevelSelect();
                //LevelSelectControl.PopulateLevels();

                XamlHelper.HideWithAnimation(BoardContainer);
                XamlHelper.HideWithAnimation(BackImage);
                XamlHelper.HideWithAnimation(RefreshImage);

                XamlHelper.ShowWithAnimation(LevelsContainer);
                XamlHelper.ShowWithAnimation(CloseImage);
                XamlHelper.ShowWithAnimation(AboutImage);

                _boardControl = null;
            }));
        }
Exemplo n.º 15
0
 /// <summary>
 /// Applies the binding.
 /// </summary>
 /// <param name="binding">The binding.</param>
 /// <param name="target">The target.</param>
 /// <param name="property">The property.</param>
 /// <param name="stringFormat">The string format.</param>
 internal void ApplyBinding(BindingBase binding, DependencyObject target, DependencyProperty property, string stringFormat)
 {
     if (binding != null)
     {
         if (stringFormat == null)
         {
             BindingOperations.SetBinding(target, property, binding);
         }
         else
         {
             BindingBase clone = (BindingBase)XamlHelper.Clone(binding);
             clone.StringFormat = stringFormat;
             BindingOperations.SetBinding(target, property, clone);
         }
     }
     else
     {
         BindingOperations.ClearBinding(target, property);
     }
 }
Exemplo n.º 16
0
        private static void OnBindableInlinesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (!(d is TextBlock Target))
            {
                return;
            }

            FlowDocument doc  = e.NewValue as FlowDocument;
            var          para = doc?.Blocks?.FirstBlock as Paragraph;

            if (para == null)
            {
                return;
            }

            Target.Inlines.Clear();
            foreach (var item in para.Inlines)
            {
                Target.Inlines.Add(XamlHelper.XamlClone(item));
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Converts a target value back to the source type.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="parameter"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        protected override Color?ConvertBack(object value, object parameter, string language)
        {
            if (value == null)
            {
                return(null);
            }
            var color = value as Color?;

            if (color != null)
            {
                return(color);
            }
            var str = value as string;

            if (str != null)
            {
                var brush = XamlHelper.CreateSolidColorBrush(str);
                return(brush.Color);
            }
            // no other conversions supported
            return(null);
        }
Exemplo n.º 18
0
        protected override void ProcessRecord()
        {
            _dispatcher.Invoke(() =>
            {
                if (InputObject != null)
                {
                    var output = InputObject.BaseObject;

                    // If the output is something that goes in a document ....
                    // Then we need to ditch our NewItemsControl and use a FlowDocumentScrollViewer
                    if (output is Block || output is Inline)
                    {
                        DocumentOutput(output);
                    }
                    else if (output is Panel)
                    {
                        _window.Content = output;
                    }
                    else
                    {
                        if (_host == null)
                        {
                            _host = XamlHelper.NewItemsControl();
                            if (_xamlUI != null)
                            {
                                _xamlUI.ContentPanel.Children.Clear();
                            }
                        }
                        if (_window == null && _host.Parent == null)
                        {
                            _xamlUI.ContentPanel.Children.Add(_host);
                        }
                        else if (_host.Items.Count == 0)
                        {
                            //    // TODO: use some template-based magic
                            //    // to FIND a predefined ItemsControl,
                            //    // or the place where they want the ItemsControl
                            //    //_window.Content
                            _window.Content = _host;//.Items.Add();
                        }

                        if (_element != null)
                        {
                            ErrorRecord err;
                            FrameworkElement el;
                            _template.TryLoadXaml(out el, out err);
                            el.DataContext = output;
                            _host.Items.Add(el);
                        }
                        else
                        {
                            _host.Items.Add(output);
                        }
                    }
                }
                else if (_element != null)
                {
                    if (_window == null)
                    {
                        _xamlUI.CurrentBlock.Inlines.Add(new InlineUIContainer(_element));
                    }
                    else
                    {
                        _window.Content = _element;
                    }
                }
            });
            WriteObject(InputObject);
        }
        public static void ReadValue(this IJSValueReader reader, out Brush value)
        {
            JSValue jsValue = JSValue.ReadFrom(reader);

            value = XamlHelper.BrushFrom((writer) => jsValue.WriteTo(writer));
        }
Exemplo n.º 20
0
 /// <inheritdoc />
 protected override DataTemplate CreateDefaultViewTemplate()
 {
     return(XamlHelper.CreateTemplate(this.GetType(), typeof(TimelineVisualizationPanelView)));
 }
Exemplo n.º 21
0
        private void CopyXaml()
        {
            var rd = XamlExporter.WrapInResourceDictionary(CurrentModel);

            Clipboard.SetText(XamlHelper.GetXaml(rd));
        }
Exemplo n.º 22
0
 /// <inheritdoc />
 protected override DataTemplate CreateDefaultViewTemplate()
 {
     return(XamlHelper.CreateTemplate(this.GetType(), typeof(InstantVisualizationContainerView)));
 }
        void NavigateToXamlValue(AbstractResolvedEntity entity)
        {
            var editor = IdeApp.Workbench.ActiveDocument.Editor;
            //first try to go to the element
            //get text at caret, and expand out till we get soem quotes
            var line   = IdeApp.Workbench.ActiveDocument.Editor.Caret.Line;
            var column = IdeApp.Workbench.ActiveDocument.Editor.Caret.Column;
            var text   = IdeApp.Workbench.ActiveDocument.Editor.GetLineText(line);

            var member = MemberExtensionsHelper.Instance.GetNearestEntity(false, true);
            //TODO get the exact property
            //var memberText = editor.GetTextBetween (member.Region.Begin, member.Region.End);

            //try to work out what this is..
//			var didPass = XamlHelper.PerformXamlNavigationActionUsingText (editor.Text);
            var isPropertyValue = XamlHelper.GetIsPropertyValue(text, column);
            var valueText       = XamlHelper.GetWordAtColumn(text, column);

            if (isPropertyValue)
            {
                if (!string.IsNullOrEmpty(valueText))
                {
                    //crude mechanism for now to work out if this is a binding statemnet or not
                    string fileName = null;
                    if (text.Contains("{"))
                    {
                        //consider that it's a property on the vm
                        //TODO make more robust.. check before opening
                        fileName = ViewModelHelper.Instance.VMFileNameForActiveDocument;
                    }
                    else
                    {
                        //consider that it's a handler on the code behind
                        //TODO make more robust.. check before opening
                        fileName = ViewModelHelper.Instance.CodeBehindFileNameForActiveDocument;
                    }
                    ViewModelHelper.Instance.OpenDocument(fileName);
                    //now go to the member
                    MemberExtensionsHelper.Instance.GotoMemberWithName(valueText);
                }
            }
            else
            {
                var unresolvedMember = member as AbstractUnresolvedMember;

                if (unresolvedMember?.ReturnType != null)
                {
                    var     returnType     = unresolvedMember.ReturnType as GetClassTypeReference;
                    var     fileNameString = returnType.FullTypeName.ReflectionName.Replace(".", "/");
                    Project targetProject;
                    var     fileName = DocumentHelper.GetFileNameWithType(fileNameString, out targetProject);

                    if (fileName != null)
                    {
                        IdeHelper.OpenDocument(fileName, targetProject);
                        if (!string.IsNullOrEmpty(valueText))
                        {
                            MemberExtensionsHelper.Instance.GotoMemberWithName(valueText);
                        }
                    }
                }
            }
        }
 /// <inheritdoc/>
 protected override DataTemplate CreateDefaultViewTemplate()
 {
     return(XamlHelper.CreateTemplate(this.GetType(), typeof(InstantVisualizationPlaceholderPanelView)));
 }