我有一个StackPanel
在我的WinRT C#Metro应用程序中,我想用作标签/值对的容器(TextBlock
和TextBox
),如下所示:
<StackPanel Orientation="Horizontal" Width="400">
<TextBlock Text="Label" Width="150" />
<TextBox Text="Value" />
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
现在我想要的是让TextBox自动填充StackPanel的剩余水平空间.这有可能吗?HorizontalAlignment
/ HorizontalContentAlignment
不工作.
我知道另一种方法是为此定义一个Grid
.问题是我有几次构造,并希望在Style
定义中使用它.我不想用行和列x次定义Grid的定义...
也许替代方案是定义一个自定义用户控件,但我希望有一个简单的可能性TextBox
来扩展.
在WinRT .NET应用程序(C#)中,我想获取在枚举值上定义的自定义属性.以下面的枚举为例:
public enum MyEnum
{
[Display(Name="Foo")]
EnumValue1,
[Display(Name="Bar")]
EnumValue2
}
Run Code Online (Sandbox Code Playgroud)
现在在"普通".NET中我知道我能够获得枚举值的自定义属性enumValue.GetType().GetMember(enumValue.ToString())
.
不幸的是,在WinRT .NET中GetMember()
,Type类上没有该方法.
有什么建议怎么搭这个?
================================================== ===
感谢下面的Marc,我找到了答案!以下代码用于从.NET 4.5 WinRT中的枚举值获取特定的自定义属性:
public static class EnumHelper
{
public static T GetAttribute<T>(this Enum enumValue)
where T : Attribute
{
return enumValue
.GetType()
.GetTypeInfo()
.GetDeclaredField(enumValue.ToString())
.GetCustomAttribute<T>();
}
}
Run Code Online (Sandbox Code Playgroud) 我们有一个使用ASP.NET Core 1.0 RC1并在IIS上托管的应用程序.它工作正常.现在我们有静态内容,可以在文件共享上使用,并且应该可以从应用程序访问.
在ASP.NET 5之前,我们在IIS中添加了一个虚拟目录,可以轻松访问共享内容.使用我们托管的ASP.NET 5应用程序,遗憾的是这似乎不起作用.我们只是404
在尝试访问静态内容时回来了.
我们的应用程序正在使用app.UseIISPlatformHandler()
和app.UseStaticFiles()
,但这不起作用.我们发现我们可以使用app.UseFileServer()
自定义FileServerOptions
来获得所需的行为,但我们很好奇是否也可以使用在IIS中添加虚拟目录的常规"旧"方式.
我有一个奇怪的问题.我有一个.NET程序,我的进程逻辑需要一个SQL Server 2005数据库上长时间运行的事务(~20分钟).没关系,因为没有人并行访问数据库.当出现问题时,应该回滚事务.
Rollback()
我的DbTransaction
对象上的操作很少且没有任何可见的模式会抛出SqlException
:
Message: "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding." StackTrace: at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error) at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult, TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParserStateObject.ReadPacket(Int32 bytesExpected) at System.Data.SqlClient.TdsParserStateObject.ReadBuffer() at System.Data.SqlClient.TdsParserStateObject.ReadByte() at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, …
在我们基于ASP.NET Core的Web应用程序中,我们需要以下内容:某些请求的文件类型应该获得自定义ContentType的响应.例如.map
应该映射到application/json
.在"完整"的ASP.NET 4.x中,与IIS结合使用,可以使用web.config <staticContent>/<mimeMap>
,我希望用自定义的ASP.NET Core中间件替换此行为.
所以我尝试了以下(简化为简洁):
public async Task Invoke(HttpContext context)
{
await nextMiddleware.Invoke(context);
if (context.Response.StatusCode == (int)HttpStatusCode.OK)
{
if (context.Request.Path.Value.EndsWith(".map"))
{
context.Response.ContentType = "application/json";
}
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,尝试context.Response.ContentType
在调用其余的中间件链后设置会产生以下异常:
System.InvalidOperationException: "Headers are read-only, response has already started."
Run Code Online (Sandbox Code Playgroud)
如何创建解决此要求的中间件?
我有几个VC++ DLL的问题,我应该将其包含在我的.NET/C#项目中.一个VC++ DLL是一个C++/CLI DLL,我将其用作.NET项目的公共接口.其他DLL是用本机C++编写的.我无法访问VC++ DLL的源代码,我只需要使用它们.
我做了一个.NET测试项目并引用了C++/CLI DLL.没问题,编译器很幸运,很棒.只有一个问题:当我启动.NET程序的EXE时,由于缺少VC++核心DLL,我得到有关C++ DLL的错误.sxstrace显示以下内容(缩写):
INFO: Reference: Microsoft.VC80.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="8.0.50727.6195"
INFO: Reference: Microsoft.VC80.OpenMP,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="8.0.50727.6195"
INFO: Resolving reference Microsoft.VC80.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="8.0.50727.6195"
...
ERROR: Cannot resolve reference Microsoft.VC80.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="8.0.50727.6195".
Run Code Online (Sandbox Code Playgroud)
现在我不是傻瓜,尝试了几件事.我已经阅读了很多关于WinSxS的内容,以便更深入地了解正在发生的事情.现在,我已经到了,我正在为我服务.我想要执行程序的系统安装了当前版本8.0.50727.762(SP1)中的VC++ Redistributable软件包.我知道winsxs中有一个针对Microsoft.VC80.CRT的策略文件,它将此程序集的所有版本重定向到当前版本8.0.50727.762(这是http://blogs.msdn.com/b/nikolad上的问题的解决方案/archive/2007/03/29/a-solution-to-two-references-to-different-versions-of-crt-mfc-atl-in-one-application-manifest-file.aspx).但正如上面的错误所说,此策略文件似乎不起作用或不予考虑.系统只想找到8.0.50727.6195版本的程序集.
现在这是第一个问题:这里的问题是什么?我搞清楚后,我可以解决最初的问题......
我必须在我的一个ASP.NET项目中包含一个(托管的)C++/CLI组件,它自己引用一些其他(非托管)C++ DLL.应该没问题 - .NET 3.5很高兴在编译项目时,一切看起来都很好.C++/CLI组件和其他C++ DLL由另一个部门编译为Visual Studio 2005中带有"Any CPU"的Release版本.安装了VC++ 2005 Redistributable软件包.当我在普通的.NET控制台应用程序中运行它时,相同的代码可以正常工作.
现在,虽然此代码在控制台应用程序中工作,但它没有被ASP.NET正确托管 - 它导致初始页面加载时出错(甚至在进入Global.asax之前).为了测试和调试,我使用了两种机器配置:
在两台计算机上,当我启动ASP.NET应用程序时出现相同的跟随错误:
Exception Details: System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[FileNotFoundException: The …
Run Code Online (Sandbox Code Playgroud) 我的WinRT/C#XAML Metro应用程序中有一个奇怪的问题,使用Windows 8 Release Preview(安装了最新的补丁).我正在使用a ComboBox
,其值ItemsSource
和SelectedValue
绑定到ViewModel中的属性:
<ComboBox SelectedValue="{Binding MySelectedValue, Mode=TwoWay}"
ItemsSource="{Binding MyItemsSource, Mode=OneWay}"
Width="200" Height="30" />
Run Code Online (Sandbox Code Playgroud)
代码背后:
public MainPage()
{
this.InitializeComponent();
DataContext = new TestViewModel();
}
Run Code Online (Sandbox Code Playgroud)
一个非常简单的定义TestViewModel
,使用字符串:
public class TestViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private IEnumerable<string> _myItemsSource = new List<string>
{
"Test Item 1",
"Test Item 2",
"Test Item 3"
};
public IEnumerable<string> MyItemsSource
{
get { return _myItemsSource; }
}
private string _mySelectedValue = "Test Item 2";
public string …
Run Code Online (Sandbox Code Playgroud) 是否有可能在WinRT中即时更改UI文化?我发现ApplicationLanguages.PrimaryLanguageOverride = "en";
,但这仅在显示应用程序UI之前有效,而不是之后(例如我想通过设置更改UI语言).
我的要求:编写一个中间件,用于过滤来自另一个后续中间件(例如Mvc)的响应中的所有"坏词".
问题:响应的流式传输.因此,当我们FilterBadWordsMiddleware
从已经写入响应的后续中间件回到我们的时候,我们对派对来说太迟了......因为响应已经开始发送,这导致了众所周知的错误response has already started
......
因此,这是许多不同情况下的要求 - 如何处理它?
asp.net-core ×3
c# ×3
.net ×2
c++ ×2
xaml ×2
.net-core ×1
asp.net ×1
attributes ×1
c++-cli ×1
culture ×1
dependencies ×1
dll ×1
iis ×1
mvvm ×1
sql-server ×1
sqlexception ×1
stackpanel ×1
textbox ×1
timeout ×1
transactions ×1
uiculture ×1
viewmodel ×1
visual-c++ ×1
windows-8 ×1
winsxs ×1