我有以下内容UserControl:
<UserControl x:Class="MyControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<SolidColorBrush x:Key="ColorKey" Color="Orange"/>
</UserControl.Resources>
<Grid Background="{StaticResource ColorKey}">
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
我这样使用它:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:OverrideResource"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<SolidColorBrush x:Key="OtherColorKey" Color="Blue"/>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<local:MyControl Grid.Row="0">
<local:MyControl.Resources>
<SolidColorBrush x:Key="ColorKey" Color="Red"/>
</local:MyControl.Resources>
</local:MyControl>
<Grid Grid.Row="1">
<Grid.Resources>
<SolidColorBrush x:Key="OtherColorKey" Color="Green"/>
</Grid.Resources>
<Grid Background="{StaticResource OtherColorKey}"/>
</Grid>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
覆盖资源OtherColorKey就像我期望的那样; 网格有绿色Background.但我想覆盖(在我的例子中)Resource内部使用的.但我得到例外:UserControlColorKey
项目已添加.键入字典:添加'ColorKey'键:'ColorKey'
这只是一个简化的例子,实际上我需要它来完成更复杂的任务.我知道,对于例如,DevExpress使用类似的机制来自定义它们的控件(但是它们不使用字符串作为键,而是使用派生的对象ResourceKey).但是我无法找到简单的工作示例来自己实现这样的事情.
谢谢你的帮助.
我有一个在IIS上运行的ASP.NET Core 2.0 Web服务.控制器的一种方法或多或少看起来像这样:
[HttpGet()]
public IActionResult Test()
{
// do some db updates and get data
var result = DoSomeStuff();
// serialize data to byte array
var output = Serialize(result);
return File(output, "application/octet-stream");
}
Run Code Online (Sandbox Code Playgroud)
它执行一些数据库更新,从表中查询记录,序列化数据并将其作为响应发送.数据以二进制格式发送.我正在使用MessagePack-CSharp作为序列化程序.
然后我有客户端应用程序与此Web服务进行通信.它是.NET Standard 2.0库,从.NET 4.6.1控制台应用程序引用.我HttpClient用于请求和HttpResponseMessage.Content.ReadAsByteArrayAsync()阅读响应(具体代码见下文).
我想做一些测试.我的桌子有cca.80列,包含cca.140000条记录.所有这些都应该发送给客户.从db获取数据需要几秒钟,然后它是序列化的所有内容和cca的结果.34MB发送给客户端.
我有10个客户.当他们连续调用webservice时,一切正常.当我强调web服务和并行启动客户端时,我几乎总是会遇到一些错误(通常有一两个失败,有时甚至是4-5).
以下是例外情况,它是从ReadAsByteArrayAsync电话中提出的:
System.AggregateException: One or more errors occurred. ---> System.Net.Http.HttpRequestException: Error while copying content to a stream. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was …Run Code Online (Sandbox Code Playgroud) 我有带有的WPF桌面应用程序Button。当我在普通PC上运行它并将鼠标指针移到按钮上时,它变为蓝色(默认Windows主题)。当我将光标移出时,按钮再次变为灰色。相当正常的行为。
但是,当我在Windows 8平板电脑上运行它时,发生了以下事情:我触摸Button,它变成蓝色。然后,我向上移动手指,但按钮保持蓝色。没有MouseLeave活动 我看到蓝色按钮,直到我单击屏幕上的其他位置。
有什么解决方法如何防止这种情况?我知道我可以删除整个悬停效果,但是除非有其他方法,否则我不想这样做。
我有一个WPF应用程序,我想在整个应用程序中修改文化设置.这是一个简化的演示,演示了我想要实现的目标:
using System.Windows;
namespace CultureProblem3
{
public partial class MainWindow : Window
{
private System.Text.StringBuilder _sb;
public MainWindow()
{
InitializeComponent();
}
private void btn_Action_Click(object sender, RoutedEventArgs e)
{
var ci = new System.Globalization.CultureInfo(System.Globalization.CultureInfo.CurrentCulture.Name);
ci.NumberFormat.NumberGroupSeparator = "xxx";
System.Globalization.CultureInfo.DefaultThreadCurrentCulture = ci;
System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = ci;
_sb = new System.Text.StringBuilder();
WriteInfo(_sb, "DefaultThreadCurrentCulture", System.Globalization.CultureInfo.DefaultThreadCurrentCulture);
WriteInfo(_sb, "DefaultThreadCurrentUICulture", System.Globalization.CultureInfo.DefaultThreadCurrentUICulture);
WriteInfo(_sb, "CultureInfo.CurrentCulture", System.Globalization.CultureInfo.CurrentCulture);
WriteInfo(_sb, "CultureInfo.CurrentUICulture", System.Globalization.CultureInfo.CurrentUICulture);
WriteInfo(_sb, "CurrentThread.CurrentCulture", System.Threading.Thread.CurrentThread.CurrentCulture);
WriteInfo(_sb, "CurrentThread.CurrentUICulture", System.Threading.Thread.CurrentThread.CurrentUICulture);
var t = new System.Threading.Thread(DoWork);
t.Start();
System.Threading.Thread.Sleep(1000);
MessageBox.Show(_sb.ToString());
}
private void DoWork()
{
WriteInfo(_sb, "CultureInfo.CurrentCulture - …Run Code Online (Sandbox Code Playgroud) 我有一个用 .NET 4.6.1 编写的 WPF 应用程序,用于平板电脑。当我聚焦文本框时,TabTip 虚拟键盘会在以下情况下自动调用:
Show the touch keyboard when not in tablet mode and there's no keyboard attached设置已打开,并且通过触摸或手写笔进行对焦Show the touch keyboard when not in tablet mode and there's no keyboard attached设置已关闭,并且使用手写笔(而非触摸)进行对焦我需要禁用这种行为。
到目前为止,我使用以下解决方法来禁用自动键盘调用:
class MyTextBox : TextBox
{
protected override AutomationPeer OnCreateAutomationPeer()
{
return new FrameworkElementAutomationPeer(this);
}
}
Run Code Online (Sandbox Code Playgroud)
从 Windows 10 版本 1803(2018 年 4 月更新)开始 - 甚至可能从 1709(秋季创作者更新)开始,但我现在无法确认 - 这不再起作用,键盘总是被调用。
有没有办法阻止我的应用程序在最新的 Windows 10 中自动显示 TabTip?
虽然它并不理想(它会影响整个系统),但我也尝试按照此处Touch …