我正在尝试用C#创建一个UWP(通用Windows应用程序)应用程序.我的问题是Frame
控制:如果我没有使用它NavigationCacheMode = Required
,每次用户返回时,页面都不会保留在内存中并将被重新创建.如果我设置NavigationCacheMode
为Required
或Enabled
返回正常工作(没有新页面对象),但如果我导航到同一类型的另一个页面,则前一页面对象将被回收并重复使用(无新页面实例).
期望的行为:
有没有办法使用原始Frame
控件具有以下行为(如在Windows Phone中):
Navigate()
GoBack()
我知道的唯一解决方案是创建一个自己的Frame
控件,但这会导致其他问题(例如:缺少SetNavigationState()
方法等...)
示例场景:
用三页的简单应用实例:TvShowListPage
,TvShowDetailsPage
,SeasonDetailsPage
.
TvShowListPage
是入口页面.点击后TvShow
导航到TvShowDetailsPage
.TvShowDetailsPage
列表中选择一个季节并导航到TvShowDetailsPage
.TvShowListPage
并选择另一个,TvShow
则TvShowDetailsPage
回收并且可能处于错误的状态(例如显示投射枢轴而不是第一个,季节枢轴)我正在寻找默认的Windows Phone 7行为:导航在页面堆栈上创建一个新页面,返回从堆栈中删除首页并显示堆栈中的上一页(存储在内存中).
解:
因为没有这个问题的解决方案,我不得不重新实现所有分页相关的类:Page,Frame,SuspensionManager等...
该库MyToolkit它提供了所有这些类可以在这里下载:https://github.com/MyToolkit/MyToolkit/wiki/Paging-Overview
参考文献:
SuspensionManager
我正在开发Windows 8应用程序.我需要知道如何以编程方式设置图像的来源.我认为Silverlight方法可行.但事实并非如此.有人知道怎么做这个吗?以下内容不起作用:
string pictureUrl = GetImageUrl();
Image image = new Image();
image.Source = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri(pictureUrl, UriKind.Relative));
image.Stretch = Stretch.None;
image.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
image.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Center;
Run Code Online (Sandbox Code Playgroud)
我得到一个异常,说:"给定的System.Uri无法转换为Windows.Foundation.Uri."
但是,我似乎无法找到Windows.Foundation.Uri类型.
我正在尝试将一个简单的应用程序移植到Windows 8 Metro(WinRT).似乎缺少一些非常基本的方法.一个基本的例子:Type.GetProperty()
.它适用于Windows Phone 7,Silverlight和.NET客户端配置文件.我是否必须安装某些东西(例如,一个特殊的库),或者这种方法在.NET metro配置文件中根本不可用?
UPDATE
好的谢谢.现在我用this.GetType().GetTypeInfo().DeclaredProperties
.
using System.Reflection;
需要有这种GetTypeInfo()
扩展方法.
我有一个保存对话框,当我按下按钮时会弹出.但是我不想在那时保存文件,我想取名称并将其放在按钮旁边的文本框中,以便稍后使用该名称.
任何人都可以告诉我如何从保存对话框中获取文件路径以便以后使用它吗?
新的NuGet版本修复了许多问题(例如,传递依赖性功能,构建时的依赖性解析,单个包存储库缓存等).
但是我只能使用ASP.NET vNext和UWP项目来测试它.
这些新功能是否也适用于"遗留"项目(例如完整的.NET 4.5/4.6项目,WPF等)?
我刚刚用CLI创建了一个新的Angular 4项目: ng new test
版本:
@angular/cli: 1.0.0
node: 6.10.0
os: win32 x64
@angular/common: 4.0.1
@angular/compiler: 4.0.1
@angular/core: 4.0.1
@angular/forms: 4.0.1
@angular/http: 4.0.1
@angular/platform-browser: 4.0.1
@angular/platform-browser-dynamic: 4.0.1
@angular/router: 4.0.1
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.1
Run Code Online (Sandbox Code Playgroud)
但是,由于我未使用的类FooBar
仍在main.*.js
文件中,因此树抖动无法正常工作.
我的示例组件TS文件(FooBar不应该在输出中):
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
}
export class FooBar {
foo = "hello";
}
Run Code Online (Sandbox Code Playgroud)
我试图使用汇总(如文档中所述),但这不起作用......
有没有一种简单的方法来启用树木摇晃?(我希望在通过CLI创建项目时默认启用它).
更新:我正在使用ng build --prod
它仍然没有被震动..
有没有办法从原始/原始JSON值JToken
?
问题:
var data = JObject.Parse(@"{
""SimpleDate"":""2012-05-18T00:00:00Z"",
""PatternDate"":""2012-11-07T00:00:00Z""
}");
var value = data["SimpleDate"].Value<string>();
Run Code Online (Sandbox Code Playgroud)
现在value
是,05/18/2012 00:00:00
但我需要原始字符串2012-05-18T00:00:00Z
.
有没有办法获得这个原始价值?另外,我无法改变JObject
创建方式(例如更改设置),因为它作为参数传递到我的类中...
(参考:最初的NJsonSchema问题)
我期望Enumerable.Empty()的实现就是这样:
public static IEnumerable<TResult> Empty<TResult>()
{
yield break;
}
Run Code Online (Sandbox Code Playgroud)
但实现是这样的:
public static IEnumerable<TResult> Empty<TResult>()
{
return EmptyEnumerable<TResult>.Instance;
}
internal class EmptyEnumerable<TElement>
{
private static volatile TElement[] instance;
public static IEnumerable<TElement> Instance
{
get
{
if (EmptyEnumerable<TElement>.instance == null)
EmptyEnumerable<TElement>.instance = new TElement[0];
return (IEnumerable<TElement>)EmptyEnumerable<TElement>.instance;
}
}
}
Run Code Online (Sandbox Code Playgroud)
为什么实现比一行代码更复杂?返回缓存数组是否有优势而不是(yield)不返回任何元素?
注意:我永远不会依赖方法的实现细节,但我只是好奇.
我ListBox
在Windows Phone 7 Silverlight中扩展了一个类的问题.想法是拥有一个完整的ScrollViewer
(黑色,例如填充整个手机屏幕),并且ItemsPresenter
(红色)有一个边距(绿色).这用于在整个列表周围有一个边距,但滚动条从右上边缘开始,到深暗矩形的右下边缘结束:
问题是,ScrollViewer
无法滚动到最后,它会从列表中的最后一个元素中删除50个像素.如果我使用StackPanel
而不是VirtualizingStackPanel
边距是正确的但是列表不再虚拟化.
感谢任何想法,我已经尝试了很多,但没有任何工作.这是一个控制错误吗?
解决方案:使用MyToolkit库中控件的InnerMargin
属性!ExtendedListBox
C#:
public class MyListBox : ListBox
{
public MyListBox()
{
DefaultStyleKey = typeof(MyListBox);
}
}
Run Code Online (Sandbox Code Playgroud)
XAML(例如App.xaml):
<Application
x:Class="MyApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">
<Application.Resources>
<ResourceDictionary>
<Style TargetType="local:MyListBox">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ScrollViewer>
<ItemsPresenter Margin="30,50,30,50" x:Name="itemsPresenter" />
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="ListBoxItem">
<Setter …
Run Code Online (Sandbox Code Playgroud) 我正在考虑将我的项目从CodePlex迁移到GitHub.
将所有内容(维基,问题等)从CodePlex迁移到GitHub的最佳方法是什么?
有人知道这样做的工具吗?
最耗时的部分是迁移所有维基页面并添加指向新家的链接.