小编Mat*_*ias的帖子

让TextBox拉伸以填充StackPanel中的宽度

我有一个StackPanel在我的WinRT C#Metro应用程序中,我想用作标签/值对的容器(TextBlockTextBox),如下所示:

<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来扩展.

xaml textbox stackpanel microsoft-metro windows-runtime

29
推荐指数
2
解决办法
6万
查看次数

获取枚举值的自定义属性

在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)

.net c# attributes windows-runtime

21
推荐指数
1
解决办法
8667
查看次数

IIS中的ASP.NET Core应用程序内的虚拟目录

我们有一个使用ASP.NET Core 1.0 RC1并在IIS上托管的应用程序.它工作正常.现在我们有静态内容,可以在文件共享上使用,并且应该可以从应用程序访问.

在ASP.NET 5之前,我们在IIS中添加了一个虚拟目录,可以轻松访问共享内容.使用我们托管的ASP.NET 5应用程序,遗憾的是这似乎不起作用.我们只是404在尝试访问静态内容时回来了.

我们的应用程序正在使用app.UseIISPlatformHandler()app.UseStaticFiles(),但这不起作用.我们发现我们可以使用app.UseFileServer()自定义FileServerOptions来获得所需的行为,但我们很好奇是否也可以使用在IIS中添加虚拟目录的常规"旧"方式.

iis virtual-directory asp.net-core

18
推荐指数
4
解决办法
2万
查看次数

SQL Server,C#:事务回滚的超时异常

我有一个奇怪的问题.我有一个.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, …

c# sql-server timeout transactions sqlexception

16
推荐指数
1
解决办法
9742
查看次数

用于设置响应ContentType的中间件

在我们基于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)

如何创建解决此要求的中间件?

c# owin-middleware asp.net-core asp.net-core-1.0

16
推荐指数
2
解决办法
4826
查看次数

WinSxS无法加载VC++ DLL

我有几个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版本的程序集.

现在这是第一个问题:这里的问题是什么?我搞清楚后,我可以解决最初的问题......

.net c++ dependencies winsxs visual-c++

10
推荐指数
1
解决办法
1万
查看次数

ASP.NET中的C++/CLI组件出现"无法找到模块"错误

我必须在我的一个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之前).为了测试和调试,我使用了两种机器配置:

  1. 本地开发PC:Windows XP,32位,VC++ 2005 Redist包,Visual Studio 2010,ASP.NET 3.5,编译"任何CPU",在Web开发服务器(Cassini)中托管
  2. 测试服务器(目标机器):Windows 7,64位,VC++ 2005 Redist包,在IIS 7中托管,AppPool具有"启用32位应用程序"集

在两台计算机上,当我启动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)

c++ asp.net dll c++-cli filenotfoundexception

9
推荐指数
2
解决办法
2890
查看次数

ComboBox SelectedValue不显示

我的WinRT/C#XAML Metro应用程序中有一个奇怪的问题,使用Windows 8 Release Preview(安装了最新的补丁).我正在使用a ComboBox,其值ItemsSourceSelectedValue绑定到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)

xaml mvvm viewmodel windows-8 windows-runtime

9
推荐指数
1
解决办法
9426
查看次数

在WinRT中更改UI文化

是否有可能在WinRT中即时更改UI文化?我发现ApplicationLanguages.PrimaryLanguageOverride = "en";,但这仅在显示应用程序UI之前有效,而不是之后(例如我想通过设置更改UI语言).

culture currentuiculture windows-runtime uiculture

8
推荐指数
1
解决办法
2082
查看次数

修改中间件响应

我的要求:编写一个中间件,用于过滤来自另一个后续中间件(例如Mvc)的响应中的所有"坏词".

问题:响应的流式传输.因此,当我们FilterBadWordsMiddleware从已经写入响应的后续中间件回到我们的时候,我们对派对来说太迟了......因为响应已经开始发送,这导致了众所周知的错误response has already started......

因此,这是许多不同情况下的要求 - 如何处理它?

.net-core asp.net-core asp.net-core-middleware

8
推荐指数
3
解决办法
5406
查看次数