using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.Logging;
using System.Collections.Generic;
namespace Infrastrcture
{
//A logger that holds on to log entries until a callback delegate is set, then plays back log entries and sends new log entries.
public class CallBackLogger:ILoggerFacade
{
private Queue> saveLogs = new Queue>();
private Action callback;
//Gets or Sets the callback to receive logs.
public Action CallBack
{
get
{
return this.callback;
}
set
{
this.callback = value;
}
}
///
/// Write a new log entry with the specified category and priority.
///
/// Message body to log.
/// Category of the entry.
/// The priority of the entry.
public void Log(string message, Category category, Priority priority)
{
if (this.CallBack != null)
{
this.CallBack(message, category, priority);
}
else
{
saveLogs.Enqueue(new Tuple(message, category, priority));
}
}
//Replay the saved logs if the Callback has been set.
public void ReplaySaveLogs()
{
if (this.CallBack != null)
{
while (this.saveLogs.Count > 0)
{
var log = this.saveLogs.Dequeue();
this.CallBack(log.Item1, log.Item2, log.Item3);
}
}
}
}
}
public class RegionNames
{
public const string NavRegion = "NavRegion";
public const string MainRegion = "MainRegion";
public const string NavDemoShowRegion = "NavDemoShowRegion";
public const string NavDemoActionRegion = "NavDemoActionRegion";
public const string TabShowRegion = "TabShowRegion";
}
public class ViewNames
{
public const string NavigationContainer = "NavigationContainer";
public const string EmptyPage = "EmptyPage";
public const string ViewA = "ViewA";
public const string ViewB = "ViewB";
public const string ViewC = "ViewC";
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Infrastrcture;
using Microsoft.Practices.Prism.Logging;
using System.Globalization;
namespace PrismRegionDemo
{
public partial class PrismRegionShell : UserControl
{
public PrismRegionShell(CallBackLogger logger)
{
InitializeComponent();
//显示当前Log信息
logger.CallBack = Log;
}
public void Log(string message, Category category, Priority priority)
{
//[Debug][Low] Setting the RegionManager.
this.LogContainer.Text += string.Format(CultureInfo.CurrentUICulture, "[{0}][{1}] {2}\r\n", category, priority, message);
//这段代码的作用是让文本框的滚动条滚动到最底部
LogContainer.Select(LogContainer.Text.Length, LogContainer.Text.Length);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.Logging;
using Infrastrcture;
namespace EmptyDemoModule
{
//ViewSortHintAttribute是为了指定哪个View先在Region中显示出来,设置为02的意思是当前排序优先级为02
[ViewSortHint("02")]
public partial class EmptyNavigationItem : UserControl
{
IRegionManager _regionManager;
ILoggerFacade logger;
public EmptyNavigationItem(IRegionManager regionManager,ILoggerFacade logger)
{
logger.Log("初始化【空示例】按钮", Category.Info, Priority.Low); //显示Log信息
InitializeComponent();
this._regionManager = regionManager;
this.logger = logger;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Uri uri = new Uri(ViewNames.EmptyPage, UriKind.Relative);
//导航到MainRegion,把Uri指向的Page显示在PrismRegionShell里命名为MainRegion的Region里
_regionManager.RequestNavigate(RegionNames.MainRegion, uri);
//显示Log信息
logger.Log("导航到Empty示例", Category.Info, Priority.Low);
}
}
}
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Prism.Logging;
using Infrastrcture;
namespace EmptyDemoModule
{
public class EmptyModule:IModule
{
IRegionManager _regionManager;
IUnityContainer _container;
ILoggerFacade logger;
public EmptyModule(IUnityContainer container,IRegionManager regionManager,ILoggerFacade logger)
{
_container = container;
_regionManager = regionManager;
this.logger = logger;
}
public void Initialize()
{
//添加显示Log信息
logger.Log("初始化Empty模块", Category.Debug, Priority.Low);
//把EmptyNavigationItem这个"按钮"View注册到RegionName为NavRegion的Region上
_regionManager.RegisterViewWithRegion(RegionNames.NavRegion, typeof(EmptyNavigationItem));
//由于EmptyPage是需要显示在ContentControl里的,同一时刻只能显示一个视图,所以在添加进去之后还需要一个Active的过程,
//因为Prism无法确定每个视图是什么类型,所以就使用了Object,因此在根据ViewName获取实例时,
//会使用IServiceLocator.GetInstance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.Logging;
using Microsoft.Practices.Unity;
namespace NavigationDemoModule
{
public partial class ActionController : UserControl
{
public ActionController(ILoggerFacade logger,IUnityContainer container)
{
logger.Log("初始化导航示例中的几个按钮的视图", Category.Info, Priority.Low);
InitializeComponent();
//指定当前Page的DataContext为ActionControllerViewModel这个ViewModel,这是MVVM架构的特性
this.Loaded += (s, e) =>
{
this.DataContext = container.Resolve();
};
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.Logging;
using Infrastrcture;
namespace NavigationDemoModule
{
[ViewSortHint("01")] //注意这个特性标示 用于在ItemControl显示时排序使用
public partial class NavigationItem : UserControl
{
IRegionManager _regionManager;
ILoggerFacade logger;
public NavigationItem(IRegionManager regionManager,ILoggerFacade logger)
{
logger.Log("初始化【导航示例】按钮", Category.Info, Priority.Low);
InitializeComponent();
this._regionManager = regionManager;
this.logger = logger;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Uri uri = new Uri(ViewNames.NavigationContainer, UriKind.Relative);
//把Region为MainRegion里的视图导航成为uri——也就是NavigationContainer的视图
_regionManager.RequestNavigate(RegionNames.MainRegion, uri);
logger.Log("导航到Navigation示例", Category.Info, Priority.Low);
}
}
}
接下来,我们来创建在NavigationContainer里要显示的另外3个View
先新建一个ViewA的UserControl:
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Prism.Logging;
namespace NavigationDemoModule
{
public partial class ViewA : UserControl
{
public ViewA(IUnityContainer container,ILoggerFacade logger)
{
InitializeComponent();
logger.Log("创建一个ViewA",Category.Info,Priority.Low);
//指定当前View的ViewModel是ViewAViewModel
this.DataContext = container.Resolve();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.Logging;
using Microsoft.Practices.Prism;
namespace NavigationDemoModule
{
//INavigationAware接口可以使视图或者其对应的ViewModel可以参加到页面导航的过程中来,
//这个接口既可以由视图来实现,也可以由视图的DataContext——也就是ViewModel来实现
public class ViewAViewModel:INavigationAware
{
ILoggerFacade logger;
public ViewAViewModel(ILoggerFacade logger)
{
this.logger = logger;
}
//当从其他页面导航到本页面的时候,首先调用该方法,判断是否要新建一个本页面还是使用原来已有该视图的实例,是否可以重用(true如果之前已经创建了ViewA的对象就使用之前的对象;false不管之前有没有创建ViewA的对象,每次导航到ViewA页面的时候都要创建一个新的ViewA对象)
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
//当从本页面导航到其他页面的时候调用该方法
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
//当从其他页面导航到该页面时候触发该方法
public void OnNavigatedTo(NavigationContext navigationContext)
{
//获取从其他页面导航到该页面时传递的参数集合Parameters
UriQuery query = navigationContext.Parameters;
//在ActionControllerViewModel里传递过来的UriQuery里有Time这个Key的值,那么在ViewA里就可以获取到该值
string time = query["Time"];
logger.Log(string.Format("ViewA:现在时间{0}", time), Category.Info, Priority.Medium);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.Logging;
namespace NavigationDemoModule
{
public partial class ViewB : UserControl,INavigationAware
{
public ViewB(ILoggerFacade logger)
{
InitializeComponent();
logger.Log("创建了一个ViewB", Category.Info, Priority.Low);
}
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return false;
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
public void OnNavigatedTo(NavigationContext navigationContext)
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.Logging;
namespace NavigationDemoModule
{
public partial class ViewB : UserControl,INavigationAware
{
public ViewB(ILoggerFacade logger)
{
InitializeComponent();
logger.Log("创建了一个ViewB", Category.Info, Priority.Low);
}
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return false;
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
public void OnNavigatedTo(NavigationContext navigationContext)
{
}
}
}
下一步创建ViewC:
ViewC的CodeBehind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.Logging;
namespace NavigationDemoModule
{
public partial class ViewC : UserControl
{
public ViewC(ILoggerFacade logger)
{
InitializeComponent();
logger.Log("创建一个ViewC", Category.Info, Priority.Low);
}
}
}
下一步是添加该项目的Module文件,新建一个NavDemoModule类:
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Prism.Logging;
using Infrastrcture;
namespace NavigationDemoModule
{
public class NavDemoModule:IModule
{
IRegionManager _regionManager;
IUnityContainer _container;
ILoggerFacade logger;
public NavDemoModule(IUnityContainer container,IRegionManager regionManager,ILoggerFacade logger)
{
_container = container;
_regionManager = regionManager;
this.logger = logger;
}
//如果一个页面相对来说不大变化,如导航区,在程序初始化的过程完成后就不会轻易变动,
//这时候就比较适合使用RegisterViewWithRegion方法,通常可以在Module的Initialize方法中完成这个过程
public void Initialize()
{
logger.Log("初始化Navigation模块", Category.Debug, Priority.Low);
_regionManager.RegisterViewWithRegion(RegionNames.NavRegion, typeof(NavigationContainer));
_regionManager.RegisterViewWithRegion(RegionNames.MainRegion, () => _container.Resolve());
_regionManager.RegisterViewWithRegion(RegionNames.NavDemoActionRegion, typeof(ActionController));
// 注意注册的类型的必须是object,因为Prism无法确定视图的类型,所以就用了object
_container.RegisterType(ViewNames.ViewA);
_container.RegisterType(ViewNames.ViewB);
_container.RegisterType(ViewNames.ViewC);
}
}
}
今天eclipse突然报了com/genuitec/eclipse/j2eedt/core/J2EEProjectUtil 错误,并且工程文件打不开了,在网上找了一下资料,然后按照方法操作了一遍,好了,解决方法如下:
错误提示信息:
An error has occurred.See error log for more details.
Reason:
com/genuitec/
Java使用按值传递的函数调用方式,这往往使我感到迷惑。因为在基础数据类型和对象的传递上,我就会纠结于到底是按值传递,还是按引用传递。其实经过学习,Java在任何地方,都一直发挥着按值传递的本色。
首先,让我们看一看基础数据类型是如何按值传递的。
public static void main(String[] args) {
int a = 2;
Implicits work like this: if you call a method on a Scala object, and the Scala compiler does not see a definition for that method in the class definition for that object, the compiler will try to con
工作与生产效率:
A. 背景声音
Noisli:背景噪音与颜色生成器。
Noizio:环境声均衡器。
Defonic:世界上任何的声响都可混合成美丽的旋律。
Designers.mx:设计者为设计者所准备的播放列表。
Coffitivity:这里的声音就像咖啡馆里放的一样。
B. 避免注意力分散
Self Co