예제 #1
0
파일: MyFrame.cs 프로젝트: DuBin1988/restv2
 private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (e.NewValue == null)
     {
         return;
     }
     MyFrame c = (MyFrame)d;
     PageResourceContentLoader load = new PageResourceContentLoader();
     load.BeginLoad(new Uri(e.NewValue.ToString(), UriKind.Relative), null, new AsyncCallback(r =>
     {
         LoadResult ui = load.EndLoad(r);
         c.Children.Clear();
         c.Children.Add((UIElement)ui.LoadedContent);
     }), 1);
 }
예제 #2
0
        public static void OnIsOpenChanged(DependencyObject dp, DependencyPropertyChangedEventArgs args)
        {
            object newVal = args.NewValue;
            //IsOpen为True,并且有子窗口名称,创建子窗口并显示
            if (newVal != null && (bool)newVal)
            {
                ChildWindowObj cwo = (ChildWindowObj)dp;
                if (cwo.CWName == null)
                {
                    throw new Exception("子窗口名称为空");
                }
                PageResourceContentLoader load = new PageResourceContentLoader();
                load.BeginLoad(new Uri(cwo.CWName + ".xaml", UriKind.Relative), null, new AsyncCallback(r =>
                {
                    LoadResult ui = load.EndLoad(r);
                    CustomChildWindow showWin = (CustomChildWindow)ui.LoadedContent;
                    if (cwo.ParamObj != null)
                    {
                        showWin.ParamValue = cwo.ParamObj;
                    }
                    showWin.Show();
                    showWin.Parent = dp;
                    //注册关闭事件获取返回值
                    showWin.Closed += (o, e) =>
                    {
                        CustomChildWindow cw = (CustomChildWindow)o;
                        if (cw.ReturnValue != null)
                        {
                            cw.ReturnValue.ToString();
                            cwo.Result = cw.ReturnValue;
                            cwo.OnCompleted();
                        }
                        cwo.OnCompleted(new AsyncCompletedEventArgs(null, false, null));
                    };
                }), 1);
                cwo.IsOpen = false;
            }

        }
예제 #3
0
 //自定义界面打印
 private void CustomPagePrint()
 {
     CustomChildWindow tipPage = null;
     PageResourceContentLoader load = new PageResourceContentLoader();
     load.BeginLoad(new Uri(messWindowName + ".xaml", UriKind.Relative), null, new AsyncCallback(r =>
     {
         LoadResult ui = load.EndLoad(r);
         tipPage = (CustomChildWindow)ui.LoadedContent;
         if (this.ParamObj != null)
         {
             tipPage.ParamValue = this.ParamObj;
             //注册关闭事件获取返回值
             tipPage.Closed += (o, e) =>
             {
                 CustomChildWindow cw = (CustomChildWindow)o;
                 if (cw.ReturnValue != null && (bool)cw.ReturnValue)
                 {
                     Print();
                 }
                 else
                 {
                     State = State.Cancle;
                     AsyncCompletedEventArgs args1 = new AsyncCompletedEventArgs(null, true, State.Cancle);
                     OnCompleted(args1);
                 }
             };
             tipPage.Show();
         }
     }), 1);
 }
예제 #4
0
 private static void OnPageNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     Panel c = (Panel)d;
     //获取页面缓存
     List<NameAndFrame> pages = GetPanelPages(c);
     //旧页面变为不可见
     if (e.OldValue != null)
     {
         NameAndFrame oldNaf = GetChildren((string)e.OldValue, pages);
         if (oldNaf != null)
         {
             oldNaf.frame.Visibility = Visibility.Collapsed;
         }
     }
     if (e.NewValue == null)
     {
         return;
     }
     string newName = (string)e.NewValue;
     //如果不包含页面,说明页面没有打开,打开页面
     NameAndFrame newui = GetChildren(newName, pages);
     if (newui == null)
     {
         PageResourceContentLoader load = new PageResourceContentLoader();
         load.BeginLoad(new Uri(e.NewValue + ".xaml", UriKind.Relative), null, new AsyncCallback(r =>
         {
             LoadResult ui = load.EndLoad(r);
             FrameworkElement page = (FrameworkElement)ui.LoadedContent; 
             c.Children.Add(page);
             //添加到页面缓存中
             NameAndFrame newpage = new NameAndFrame(newName, page);
             pages.Add(newpage);
         }), 1);
     }
     else
     {
         //修改页面为可见
         newui.frame.Visibility = Visibility.Visible;
         //将新的放到栈顶
         pages.Remove(newui);
         pages.Add(newui);
     }
 }
예제 #5
0
        private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ContentControl c = (ContentControl)d;
            if (e.NewValue == null)
            {
                return;
            }

            // 如果是加载网页组件,产生网页组件,把网页名称给网页组件
            if (e.NewValue.Equals("html.xaml"))
            {
                Html html = new Html();
                c.Content = html;
                // 把网页名称给网页组件
                html.Source = GetHtmlSource((Frame)c);
                return;
            }

            PageResourceContentLoader load = new PageResourceContentLoader();
            load.BeginLoad(new Uri(e.NewValue + ".xaml", UriKind.Relative), null, new AsyncCallback(r =>
            {
                LoadResult ui = load.EndLoad(r);        
                c.Content = ui.LoadedContent;
            }), 1);
        }