在WP7和WP8中,我只需要清除页面中的backstack,然后按Back按钮关闭应用程序.在WP8.1中,我执行Frame.BackStack.Clear(),按Back并且应用程序最小化..如何使用Back按钮将其杀死?
我正在使用MVVM Light.当我在我的资源中添加更多值转换器时,我的应用程序崩溃,但异常:
Microsoft.Practices.ServiceLocation.DLL中出现"System.InvalidOperationException"类型的异常,但未在用户代码中处理
附加信息:必须设置ServiceLocationProvider.
在App.xaml.csOnLaunched活动中,我有这一行
ServiceLocator.Current.GetInstance<MyViewModel>();
Run Code Online (Sandbox Code Playgroud)
它在那里崩溃..在这个ServiceLocator中我可以看到有一个SetLocatorProvider方法,它接受ServiceLocatorProvider作为参数.我无法在Web和微软MSDN页面上找到任何内容:
protected override async void OnLaunched(LaunchActivatedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
...
}
if (rootFrame.Content == null)
{
...
}
Window.Current.Activate();
DispatcherHelper.Initialize();
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
ServiceLocator.Current.GetInstance<MyViewModel>();
}
Run Code Online (Sandbox Code Playgroud)
编辑:这是完整的OnLaunched活动.放完之后
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
Run Code Online (Sandbox Code Playgroud)
发生异常:
GalaSoft.MvvmLight.Extras.DLL中发生了类型Microsoft.Practices.ServiceLocation.ActivationException'的异常,但未在用户代码中处理
其他信息:在缓存中找不到类型:cMC.ViewModel.MyViewModel.
这是ViewModelLocator的代码
public class ViewModelLocator
{
public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
SimpleIoc.Default.Register<MyViewModel>();
}
public MyViewModel MyVM
{
get
{
return ServiceLocator.Current.GetInstance<MyViewModel>();
}
}
public static void Cleanup() {}
}
Run Code Online (Sandbox Code Playgroud) 所以在我使用之前:
System.Threading.Thread.CurrentThread.CurrentCulture
Run Code Online (Sandbox Code Playgroud)
如何在Wp8.1中完成.为什么所有被弃用的东西都没有很好的文档,你可以像xCode一样使用?
所以在WP7和WP8中,我在Page2中做了这个,知道我是否来自Page1:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
var lastPage = NavigationService.BackStack.FirstOrDefault();
if (null != lastPage && true == lastPage.Source.ToString().Contains("Page1.xaml"))
{
}
}
Run Code Online (Sandbox Code Playgroud)
怎么做WP8.1?
如何轻松防止0成为使用JavaScript在文本框中输入的第一个字符?我想要像.Net这样的东西OnKeyDown().当用户按下0要防止的第一个字符的键时
e.Handled = true;
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用?
function PreventFirstCharZero()
{
var TB = document.getElementById("idbox").value;
var TextLength = TB.value.length;
if (48 == event.keyCode && 0 == TextLength)
{
event.preventDefault();
}
}
Run Code Online (Sandbox Code Playgroud)
这不起作用
function PreventFirstCharZero()
{
if ('0' == document.getElementById("idbox")[0].value)
{
event.preventDefault();
}
}
Run Code Online (Sandbox Code Playgroud) 在我的Windows Phone 8.1应用程序中,我想获取当前页面类型,如果它与我的检查匹配以刷新该页面.怎么做?这不起作用:
Frame rootFrame = Window.Current.Content as Frame;
Run Code Online (Sandbox Code Playgroud) c# windows-phone windows-phone-8 windows-8.1 windows-phone-8.1
假设我有一个像这样的对象列表
list <type>
---------------
o1: date-23.03
o2: date-23.03
o3: date-24.05
o4: date-25.05
Run Code Online (Sandbox Code Playgroud)
如何制作另一个包含具有相同日期的对象内部列表的列表?例如:
new list<list<type>>
-----------------------
List<type> innerList1 {o1, o2}
List<type> innerList2 {o3}
List<type> innerList3 {o4}
Run Code Online (Sandbox Code Playgroud)
可能的LINQ解决方案很酷,但算法也不错.
所以如果我有这个带有xml的示例字符串.
"<bookstore>
<book genre='autobiography' publicationdate='1981-03-22' ISBN='1-861003-11-0'>
<title>The Autobiography of Benjamin Franklin</title>
<author age="40">
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<author age="56">
<first-name>Barack</first-name>
<last-name>Obama</last-name>
</author>
<price>8.99</price>
</book>
</bookstore>"
Run Code Online (Sandbox Code Playgroud)
我想从它做两个不同的字符串如下:
"<author age="40">
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>"
Run Code Online (Sandbox Code Playgroud)
和
"<author age="56">
<first-name>Barack</first-name>
<last-name>Obama</last-name>
</author>"
Run Code Online (Sandbox Code Playgroud)
因为我想把它们放在List中.我尝试使用Split但没有结果
我在反序列化XML文档时遇到问题.它给了我:
XML文档中存在错误(1,23).---> System.InvalidOperationException:没想到.
这是我的XML:
<?xml version="1.0" ?>
<car>
<msg>asdfgg</msg>
<userGUID>234234</userGUID>
<event>vfrewvwev</event>
</car>
Run Code Online (Sandbox Code Playgroud)
这是我生成的类:
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xsd2Code", "3.4.0.37595")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class car: System.ComponentModel.INotifyPropertyChanged {...
Run Code Online (Sandbox Code Playgroud)
这是我使用的反序列化方法:
MyApp ma = MyApp.Deserialize(strXml);
public static MyApp Deserialize(string xml)
{
System.IO.StringReader stringReader = null;
try
{
stringReader = new System.IO.StringReader(xml);
return ((MyApp)(Serializer.Deserialize(System.Xml.XmlReader.Create(stringReader))));
}
finally
{
if ((stringReader != null))
{
stringReader.Dispose();
}
}
}
Run Code Online (Sandbox Code Playgroud) 我想根据我的对象的属性删除重复项:
public class MyType
{
public string _prop1;
public string _prop2;
public LocationsClass(string prop1, string prop2)
{
_prop1= prop1;
_prop2= prop2;
}
}
...
List<MyType> myList;
Run Code Online (Sandbox Code Playgroud)
所以基本上我想从myList中删除所有MyType对象,在_prop1中使用相同的值.有没有办法做到这一点,可能与LINQ?
为什么我的方法GetList()在linq语句后返回null?
public static List<MyType> GetListOfAllLocations()
{
var DistinctList = ListWith25Elements.GroupBy(x => x.id).Select(y => y.First());
return DistinctList as List<MyType>
}
Run Code Online (Sandbox Code Playgroud)
...
foreach(MyType mt in GetListOfAllLocations())... // this is null?!?!
Run Code Online (Sandbox Code Playgroud)