Ejemplo n.º 1
0
        void _gridClickManager_DoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGridRow dgrow = sender as DataGridRow;
            PageResourceContentLoader load = new PageResourceContentLoader();

            load.BeginLoad(new Uri(page + ".xaml", UriKind.Relative), null, new AsyncCallback(r =>
            {
                LoadResult ui             = load.EndLoad(r);
                CustomChildWindow showWin = (CustomChildWindow)ui.LoadedContent;
                showWin.ParamValue        = dgrow.DataContext;
                showWin.Show();
            }), 1);
        }
Ejemplo n.º 2
0
 public ModalWindow()
 {
     childWindow = new CustomChildWindow()
     {
         ShowMaxButton  = false,
         ShowMinButton  = false,
         Modal          = true,
         Resize         = false,
         MinVertical    = 30,
         OverlayOpacity = 0.65
     };
     childWindow.Style = Application.Current.Resources[ChildWindowStyleKey] as Style;
     RegisterEvent();
     childWindow.Tag = this;
 }
Ejemplo n.º 3
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;
            }
        }
        /// <summary>
        /// 扩充后的根据名称找对象的方法,如果名字=this, 返回自己;名字=data, 返回数据上下文。
        /// 其它,先在界面上找元素,没找到,在自己的资源里找,没找到,一直往上找父资源的,都没有找到,
        /// 在应用程序资源中找。
        /// </summary>
        /// <param name="ui"></param>
        public static object FindResource(this FrameworkElement ui, string name)
        {
            //如果是this,返回所附加到的对象
            if (name == "this")
            {
                return(ui);
            }
            //是data,返回数据上下文
            if (name == "data")
            {
                return(ui.DataContext);
            }
            //在界面上找元素
            object fui = ui.FindName(name);

            if (fui != null)
            {
                return(fui);
            }
            //找资源
            object result = FindResourceInSelf(ui, name);

            if (result != null)
            {
                return(result);
            }
            ui = ui.GetParent();
            while (ui != null)
            {
                //在界面上找元素
                fui = ui.FindName(name);
                if (fui != null)
                {
                    return(fui);
                }
                result = FindResourceInSelf(ui, name);
                if (result != null)
                {
                    return(result);
                }
                if (ui is CustomChildWindow)
                {
                    CustomChildWindow ccw = (CustomChildWindow)ui;
                    result = ccw.Parent.FindResource(name);
                    if (result != null)
                    {
                        return(result);
                    }
                }
                ui = ui.GetParent();
            }
            //在界面上没找到,在应用程序中找
            if (Application.Current.Resources.Contains(name))
            {
                return(Application.Current.Resources[name]);
            }
            //在应用程序中没找到,在应用程序的主页面中找
            result = GetResourceFromFrame(name);
            if (result != null)
            {
                return(result);
            }
            //if (ui is Table)
            //{
            //    return ((Table)ui).MainData;
            //}
            return(null);
        }