public object Read(string xaml)
        {
            if (string.IsNullOrEmpty(xaml))
            {
                return(null);
            }
            var node = XamlUtil.GetNode(xaml);

            if (node == null)
            {
                return(null);
            }
            XmlnsDictionary.Collect(node);

            //创建元素
            var obj  = ComponentFactory.Create(node.OriginalName);
            var type = obj as Type;

            if (type != null)
            {
                //是基础类型
                return(DataUtil.ToValue(node.InnerHtml, type));
            }
            else
            {
                Load(obj, node);
            }
            return(obj);
        }
 async void ViewSource_Clicked(object sender, System.EventArgs e)
 {
     await Navigation.PushAsync(new ViewSourcePage
     {
         Source = XamlUtil.GetXamlForType(typeof(ThreeTwoPage))
     });
 }
        public override void OnNavigatedTo(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            if (state.Any())
            {
                // clear any cache
                state.Clear();
            }
            else
            {
                // use navigation parameter
                var locator       = XamlUtil.GetResource <ViewModelLocator>("Locator", null);
                var peopleService = locator.PeopleService;

                var people = peopleService.People;

                _personViewModel = people.FirstOrDefault(p => p.Person.Id == parameter.ToString());

                if (_personViewModel != null)
                {
                    IsLoading = true;
                    Shell.SetBusyVisibility(Visibility.Visible, "Loading...");
                    peopleService.LoadDetails(_personViewModel.Person)
                    .ContinueWith(t =>
                    {
                        IsLoading = false;
                        Shell.SetBusyVisibility(Visibility.Collapsed);
                    });

                    var currentRank = _personViewModel.Person.Stats.Rank;
                    _prev = people.FirstOrDefault(p => p.Person.Stats.Rank == currentRank - 1);
                    _next = people.FirstOrDefault(p => p.Person.Stats.Rank == currentRank + 1);
                }
            }
        }
Example #4
0
        private void Update()
        {
            var controls = XamlUtil.AllChildren <Control>(commandBar);
            var button   = controls.OfType <Button>().FirstOrDefault(x => x.Name.Equals("MoreButton"));

            if (button == null)
            {
                return;
            }
            switch (Visibility)
            {
            case Visibilities.Visible:
                button.Visibility = global::Windows.UI.Xaml.Visibility.Visible;
                break;

            case Visibilities.Collapsed:
                button.Visibility = global::Windows.UI.Xaml.Visibility.Collapsed;
                break;

            case Visibilities.Auto:
                var count = commandBar.PrimaryCommands.OfType <Control>().Count(x => x.Visibility.Equals(global::Windows.UI.Xaml.Visibility.Visible));
                count            += commandBar.SecondaryCommands.OfType <Control>().Count(x => x.Visibility.Equals(global::Windows.UI.Xaml.Visibility.Visible));
                button.Visibility = (count > 0) ? global::Windows.UI.Xaml.Visibility.Visible : global::Windows.UI.Xaml.Visibility.Collapsed;
                break;
            }
        }
Example #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
            });

            Action updateEllipse = () =>
            {
                var controls = XamlUtil.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();
        }
 private async void ViewXAML()
 {
     var source = XamlUtil.GetXamlForType(typeof(ControlPage));
     await Shell.Current.Navigation.PushAsync(new ViewSourcePage
     {
         Source = source
     });
 }
 private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
 {
     var headers = XamlUtil.AllChildren<PivotHeaderItem>(this);
     foreach (var headerItem in headers)
     {
         headerItem.Height = double.NaN;
     }
 }
Example #8
0
        public void Serialize_Deserialize(bool formatted)
        {
            var str  = "abcd";
            var text = XamlUtil.Serialize(str, formatted);
            // Console.WriteLine(text);

            var deser = XamlUtil.Deserialize <string>(text);

            Assert.AreEqual(deser, str);
        }
Example #9
0
        /// <summary>
        /// 右键菜单展开事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnContextMenuOpen(object sender, ContextMenuEventArgs e)
        {
            XamlUtil.SelectRow(PasswordDataGrid, e);
            var selected = PasswordDataGrid.SelectedItem;

            if (null == selected)
            {
                e.Handled = true;
            }
        }
        async void ViewSource_Clicked(object sender, System.EventArgs e)
        {
            await Navigation.PushAsync(new ViewSourcePage
            {
                Source = XamlUtil.GetXamlForType(typeof(ThreeOnePage))
            });

            //var choice = await DisplayActionSheet("Actions", "Close", "destroy",
            //"Release Notes",
            //"View XAML Source",
            //"Documentation");
        }
        /// <summary>
        /// 具体同步项右击事件, 移除项目
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ImgItemRightClick(object sender, MouseButtonEventArgs e)
        {
            if (mSyncFileBgWorker.IsBusy)
            {
                //正在同步时不允许删除项
                return;
            }
            var subListView = XamlUtil.GetParentListView(e);
            //根据触发按钮获取点击的行
            var selected    = ((ListViewItem)subListView.ContainerFromElement(sender as StackPanel)).Content;
            var ImgItemList = (ObservableCollection <DeviceSyncItem>)subListView.ItemsSource;

            ImgItemList.Remove(selected as DeviceSyncItem);
        }
Example #12
0
        protected override void Draw(PageBrush brush)
        {
            var ui = (this.BelongTemplate.TemplateParent as UIElement);

            if (ui == null)
            {
                return;
            }
            var attrs = ui.Attributes;

            brush.Backspace(1); //移除 >
            XamlUtil.OutputAttributes(attrs, brush);
            brush.Draw(">");
        }
Example #13
0
        public MainPageViewModel()
        {
            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                // designtime data
                return;
            }

            SortByRankCommand = new DelegateCommand(() => ChangeSort(PeopleSort.Rank));
            SortByNameCommand = new DelegateCommand(() => ChangeSort(PeopleSort.Name));

            var locator = XamlUtil.GetResource <ViewModelLocator>("Locator", null);

            _peopleService = locator.PeopleService;
        }
        /// <summary>
        /// 加载xaml文件中的信息到obj中
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="xaml"></param>
        /// <param name="connector"></param>
        public void Load(object obj, string xaml)
        {
            if (obj == null)
            {
                return;
            }
            var node = XamlUtil.GetNode(xaml);

            if (node == null)
            {
                return;
            }
            XmlnsDictionary.Collect(node);
            Load(obj, node);
        }
Example #15
0
        private string GetColumnTemplateCode(UIElementCollection content)
        {
            string code = string.Empty;

            using (var temp = StringPool.Borrow())
            {
                var sb = temp.Item;
                foreach (UIElement item in content)
                {
                    var ec = XamlUtil.GetCode(item);
                    sb.AppendLine(ec);
                }
                code = sb.ToString();
            }
            return(code);
        }
        private void OutputAttributes(StringBuilder code)
        {
            var attached = this.AttachedAttributes;
            var local    = this.Attributes;

            //先打印附加属性
            foreach (var item in attached)
            {
                var attr = item as CustomAttribute;
                if (local.GetAttribute(attr.Name) != null)
                {
                    continue;                                        //本地属性有,那么不打印,这意味着输出本地属性
                }
                XamlUtil.OutputAttribute(attr, code);
            }
            XamlUtil.OutputAttributes(local, code);
        }
Example #17
0
        private void UpdateEllipse()
        {
            if (_commandBar == null)
            {
                return;
            }
            var controls = XamlUtil.AllChildren <Control>(_commandBar);
            var buttons  = controls.OfType <Button>();
            var button   = buttons.FirstOrDefault(x => x.Name.Equals("MoreButton"));

            if (button != null)
            {
                var count =
                    _commandBar.PrimaryCommands.OfType <Control>().Count(x => x.Visibility.Equals(Visibility.Visible));
                count            += _commandBar.SecondaryCommands.OfType <Control>().Count(x => x.Visibility.Equals(Visibility.Visible));
                button.Visibility = (count > 0) ? Visibility.Visible : Visibility.Collapsed;
            }
        }
Example #18
0
        private static IPendingHandler CallPendingBox(Window owner, string message, string caption, bool canCancel)
        {
            return((IPendingHandler)Application.Current.Dispatcher.Invoke(new Func <IPendingHandler>(() =>
            {
                var setting = PendingBoxSettings.Setting;
                var windowStyle = XamlUtil.ToXaml(setting.WindowStyle);
                var cancelButtonStyle = XamlUtil.ToXaml(setting.CancelButtonStyle);
                var contentTemplate = XamlUtil.ToXaml(setting.ContentTemplate);
                var spinnerStyle = XamlUtil.ToXaml(setting.SpinnerStyle);
                var createOnNewThread = setting.CreateOnNewThread;
                var cancelButtonContent = setting.CancelButtonContent;
                var interopOwnersMask = setting.InteropOwnersMask;
                var handler = new PendingHandlerImpl();
                var ownerRect = GetOwnerRect(owner);

                if (createOnNewThread)
                {
                    var autoReset = new AutoResetEvent(false);
                    var thread = new Thread(() =>
                    {
                        var pendingWindow = new PendingBoxWindow(owner, interopOwnersMask, ownerRect, message, caption, canCancel, windowStyle, cancelButtonStyle, spinnerStyle, contentTemplate, cancelButtonContent, handler);
                        pendingWindow.Closed += delegate
                        {
                            pendingWindow.Dispatcher.InvokeShutdown();
                        };
                        pendingWindow.Show();
                        autoReset.Set();
                        Dispatcher.Run();
                    });
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.IsBackground = true;
                    thread.Start();
                    autoReset.WaitOne();
                }
                else
                {
                    var pendingWindow = new PendingBoxWindow(owner, interopOwnersMask, null, message, caption, canCancel, windowStyle, cancelButtonStyle, spinnerStyle, contentTemplate, cancelButtonContent, handler);
                    pendingWindow.Show();
                }

                return handler;
            })));
        }
        public PendingBoxWindow(Window owner, bool interopOwnersMask, Rect?ownerRect, string message, string caption, bool canCancel, string windowStyle, string cancelButtonStyle, string spinnerStyle, string contentTemplate, object cancelButtonContent, PendingHandlerImpl handler)
        {
            _captionText = caption;
            _messageText = message;
            _canCancel   = canCancel;

            _cancelButtonContent = cancelButtonContent;

            _handler = handler;
            _handler.SetWindow(this);


            Style              = XamlUtil.FromXaml <Style>(windowStyle);
            ContentTemplate    = XamlUtil.FromXaml <DataTemplate>(contentTemplate);
            _cancelButtonStyle = XamlUtil.FromXaml <Style>(cancelButtonStyle);
            _spinnerStyle      = XamlUtil.FromXaml <Style>(spinnerStyle);

            if (ownerRect == null)
            {
                WindowStartupLocation = owner == null
                  ? WindowStartupLocation.CenterScreen
                  : WindowStartupLocation.CenterOwner;
            }

            if (ownerRect == null)
            {
                Owner = owner;
            }
            else
            {
                _ownerRect = ownerRect;
                Topmost    = true;
            }
            if (owner is WindowX ownerX && interopOwnersMask)
            {
                ownerX.Dispatcher.BeginInvoke(new Action(() =>
                {
                    ownerX.IsMaskVisible = true;
                }));
                _owner = ownerX;
            }
            Loaded += PendingBoxWindow_Loaded;
        }
Example #20
0
 public INoticeHandler AddItem(string message, string caption, MessageBoxIcon icon, ImageSource imageIcon, int?duration, bool canClose, TimeSpan animationDuration, string noticeBoxItemStyle)
 {
     return((INoticeHandler)Dispatcher.Invoke(new Func <INoticeHandler>(() =>
     {
         var noticeBoxItem = new NoticeBoxItem(animationDuration, duration)
         {
             Style = XamlUtil.FromXaml <Style>(noticeBoxItemStyle),
             Caption = caption,
             Message = message,
             Icon = icon,
             ImageIcon = imageIcon,
             CanClose = canClose,
         };
         noticeBoxItem.Closed += NoticeBoxItem_Closed;
         noticeBoxItem.Click += NoticeBoxItem_Click;
         _noticeHandler = new NoticeHandlerImpl(noticeBoxItem);
         _astkItems.Children.Add(noticeBoxItem);
         return _noticeHandler;
     })));
 }
Example #21
0
        /// <summary>
        /// 右键删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnClickContextMenuDelete(object sender, MouseButtonEventArgs e)
        {
            XamlUtil.SelectRow(DnsRecordDataGrid, e);
            var selected = DnsRecordDataGrid.SelectedItem as DnsRecord;

            if (null == selected)
            {
                return;
            }
            var result = new ConfirmDialog(AlertLevel.WARN, string.Format((string)Application.Current.FindResource("DeleteConfirm"), selected.Name)).ShowDialog();

            if (result.GetValueOrDefault())
            {
                mTenCloudDns.DelDNSRecord(Convert.ToString(selected.id), response =>
                {
                    var resultData = response.Data;
                    LoadDnsRecord();
                });
            }
        }
Example #22
0
        private static INoticeHandler Show(string message, string caption, bool canClose, MessageBoxIcon icon, ImageSource imageIcon, int?duration)
        {
            return((INoticeHandler)Application.Current.Dispatcher.Invoke(new Func <INoticeHandler>(() =>
            {
                var setting = NoticeBoxSettings.Setting;
                var animationEase = setting.AnimationEase;
                var animationDuration = setting.AnimationDuration;
                var noticeBoxItemStyle = XamlUtil.ToXaml(setting.NoticeBoxItemStyle);
                var createOnNewThread = setting.CreateOnNewThread;

                if (_noticeWindow == null)
                {
                    if (createOnNewThread)
                    {
                        var autoReset = new AutoResetEvent(false);
                        _thread = new Thread(() =>
                        {
                            _noticeWindow = new NoticeBoxWindow(animationEase, animationDuration);
                            _noticeWindow.Closed += delegate
                            {
                                _noticeWindow.Dispatcher.InvokeShutdown();
                            };
                            _noticeWindow.Show();
                            autoReset.Set();
                            Dispatcher.Run();
                        });
                        _thread.SetApartmentState(ApartmentState.STA);
                        _thread.IsBackground = true;
                        _thread.Start();
                        autoReset.WaitOne();
                    }
                    else
                    {
                        _noticeWindow = new NoticeBoxWindow(animationEase, animationDuration);
                        _noticeWindow.Show();
                    }
                }
                var handler = _noticeWindow.AddItem(message, caption, icon, imageIcon, duration, canClose, animationDuration, noticeBoxItemStyle);
                return handler;
            })));
        }
Example #23
0
        /// <summary>
        /// 同步规则删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnSyncConfigItemMouseRightClick(object sender, MouseButtonEventArgs e)
        {
            XamlUtil.SelectRow(SyncPathDataGrid, e);
            var selected = SyncPathDataGrid.SelectedItem as SyncConfigViewModel;

            if (null == selected)
            {
                return;
            }
            //删除对话框
            var result = new ConfirmDialog(AlertLevel.WARN, string.Format((string)Application.Current.FindResource("DeleteConfirm"), string.Format("{0}", selected.PcPath))).ShowDialog();

            if (result.GetValueOrDefault())
            {
                SQLite.ExecuteNonQuery("DELETE FROM media_sync_config WHERE ID = @id", new List <SQLiteParameter> {
                    new SQLiteParameter("@id", selected.Id)
                });
                var vm = DataContext as SettingsViewModel;
                vm.SyncConfigs.Remove(selected);
                vm.CheckSyncConfigIsCheckedAll(true);
            }
        }
Example #24
0
        private void DrawBegin(PageBrush brush)
        {
            brush.Draw("<a href='javascript:;'");
            if (!string.IsNullOrEmpty(this.Color))
            {
                if (this.Outline > 0)
                {
                    brush.DrawFormat(" class='btn btn-outline-{0} m-btn", this.Color);
                }
                else
                {
                    brush.DrawFormat(" class='btn btn-{0} m-btn", this.Color);
                }
            }
            else
            {
                brush.Draw(" class='btn m-btn");
            }

            if (!string.IsNullOrEmpty(this.Hover))
            {
                brush.DrawFormat(" m-btn--hover-{0}", this.Hover);
            }

            if (!string.IsNullOrEmpty(this.Icon))
            {
                brush.Draw(" m-btn--icon");
                if (string.IsNullOrEmpty(this.Text))
                {
                    brush.Draw(" m-btn--icon-only");
                }
            }

            if (!string.IsNullOrEmpty(this.Size))
            {
                if (this.Size.EqualsIgnoreCase("custom"))
                {
                    brush.Draw(" m-btn--custom");
                }
                else
                {
                    brush.DrawFormat(" btn-{0}", this.Size);
                }
            }

            if (this.Outline > 1)
            {
                brush.DrawFormat(" m-btn--outline-{0}x", this.Outline);
            }

            if (!string.IsNullOrEmpty(this.Shape))
            {
                brush.DrawFormat(" m-btn--{0}", this.Shape);
            }

            if (this.Air)
            {
                brush.Draw(" m-btn--air");
            }

            if (!string.IsNullOrEmpty(this.Class))
            {
                brush.DrawFormat(" {0}", this.Class);
            }


            brush.Draw("' "); //class输出完毕

            XamlUtil.OutputAttributes(this.Attributes, brush);

            if (!string.IsNullOrEmpty(this.ProxyCode))
            {
                brush.DrawFormat(" data-proxy=\"{0}\" ", this.ProxyCode);
            }

            XamlUtil.OutputAttributes(this.Attributes, brush);

            brush.DrawLine(">");
        }
        /// <summary>
        /// 项目双击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ImgItemLeftClick(object sender, MouseButtonEventArgs e)
        {
            var subListView = XamlUtil.GetParentListView(e);
            //根据触发按钮获取点击的行
            var selected    = (DeviceSyncItem)((ListViewItem)subListView.ContainerFromElement(sender as StackPanel)).Content;
            var curTimeMill = TimeUtil.CurrentMillis();
            var lastClick   = selected.LastLeftMouseClickTime;

            selected.LastLeftMouseClickTime = curTimeMill;
            //双击才执行操作
            if (curTimeMill - lastClick < 200)
            {
                if (selected.SourceView == SyncDeviceType.PC)
                {
                    //如果文件存在于PC, 则打开文件
                    System.Diagnostics.Process.Start(Path.Combine(selected.FolderView, selected.NameView));
                }
                else
                {
                    //不允许重复调用
                    if (selected.IsCopying)
                    {
                        return;
                    }

                    //读取系统的临时文件夹
                    var winTempFolder = Path.GetTempPath();
                    if (null == winTempFolder)
                    {
                        OnTaskBarEvent?.Invoke(new MainWindowStatusNotify
                        {
                            message    = "无法获取临时文件夹",
                            alertLevel = AlertLevel.ERROR,
                        });
                        return;
                    }
                    var targetFullPath = Path.Combine(winTempFolder, selected.NameView);
                    //如果已经存在于临时文件夹, 则直接打开
                    if (System.IO.File.Exists(targetFullPath))
                    {
                        System.Diagnostics.Process.Start(targetFullPath);
                        return;
                    }

                    //发送进度消息
                    selected.IsCopying = true;
                    OnTaskBarEvent?.Invoke(new MainWindowStatusNotify
                    {
                        message     = "正在复制文件",
                        alertLevel  = AlertLevel.RUN,
                        nowProgress = 99
                    });
                    //先复制目标文件到临时文件夹, 再打开
                    using (var device = (MediaDevice)DeviceListCombobox.SelectedItem)
                    {
                        device.Connect();
                        var           filePath = Path.Combine(((DeviceDriverViewModel)DriverListCombobox.SelectedItem).ValueView, selected.FolderView, selected.NameView);
                        MediaFileInfo fileInfo = device.GetFileInfo(filePath);
                        fileInfo.CopyTo(targetFullPath);
                        device.Disconnect();
                    }
                    selected.IsCopying = false;
                    OnTaskBarEvent?.Invoke(new MainWindowStatusNotify
                    {
                        message = string.Format("已复制到临时文件夹 {0}", targetFullPath)
                    });
                    System.Diagnostics.Process.Start(targetFullPath);
                }
            }
            else
            {
                //显示文件名
                OnTaskBarEvent?.Invoke(new MainWindowStatusNotify
                {
                    message = string.Format("{0}", Path.Combine(selected.FolderView, selected.NameView))
                });
            }
        }