我使用drawable作为TextView的背景,只是在文本下面有一个分隔线.用这个drawable-xml来解决它:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:shape="rectangle">
<solid android:color="#FFDDDDDD" />
<gradient
android:angle="0"
android:startColor="#FFAAAAAA"
android:endColor="#FFEEEEEE"
/>
</shape>
</item>
<item android:bottom="2dp">
<shape
android:shape="rectangle">
<solid android:color="#FF000000" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
但是这种方法在黑色矩形上方绘制一个彩色矩形.我想只在形状底部的线条没有黑色矩形,因为黑色不透明.我怎么能实现这一目标?
我有一个完整的ASP.NET MVC应用程序(由5个程序集组成,.NET 4.5.1,ASP.NET MVC 5.2.2),它在Visual Studio(使用IISExpress)中运行良好.
我现在想要一个控制台应用程序,它接受MVC应用程序并托管它(自托管).
我尝试过Microsoft.Owin.Host.HttpListener,Nancy.Owin但是当我得到404页面时,我的配置缺少映射到我的MVC应用程序.
我有
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseNancy();
}
}
Run Code Online (Sandbox Code Playgroud)
和
static void Main(string[] args)
{
StartOptions so = new StartOptions("http://localhost:9000/");
using (WebApp.Start<Startup>(so))
{
Console.WriteLine("Press Enter to Exit");
Console.ReadLine();
}
}
Run Code Online (Sandbox Code Playgroud)
但显然MyMvcApplication缺少从正在运行的MVC应用程序中使用的配置.怎么做?或者如何自我托管呢?
我在网上找到的答案是指旧版本,我希望今天有更简单的方法.
在a WindowsFormsHost和选项卡导航中托管WinForms表单时遇到了问题.要解决我已经做了这个简单的例子:
Window(应用程序的起点)Form了两个TextBox上面的WinFormsWindowsFormsHost到它OnLoaded处理程序Textbox定位在WindowsFormsHost在OnLoaded我得到的处理程序中:
System.Windows.Forms.Form f = new WinFormsForm();
f.TopLevel = false;
f.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.windowsFormsHost1.Child = f;
Run Code Online (Sandbox Code Playgroud)
当我现在运行应用程序时:
TextBox在WindowsFormsHost,它获得焦点(OK)TextBox中WindowsFormsHost(OK)TextBox的WindowsFormsHost(不 ok了;应该已经离开WindowsFormsHost,并在WPF窗口底部给予重点的文本框)WindowsFormsHost),它得到焦点(确定)WindowsFormsHost- 因为它应该在结束后开始.所以这也没关系WindowsFormsHost(ok)WindowsFormsHost(去在WFH开始)(未确认)如果我只有一种类型的控件,我如何使焦点行为?在这种情况下,意味着WFH-1st-Textbox,WFH-2nd-Textbox,WPF-Textbox的Tab键顺序.
C#7.0(在VS 2017中)的新功能是否可以将元组字段名称转换为KeyValuePairs?
让我们假设我有这个:
class Entry
{
public string SomeProperty { get; set; }
}
var allEntries = new Dictionary<int, List<Entry>>();
// adding some keys with some lists of Entry
Run Code Online (Sandbox Code Playgroud)
做一些像这样的事情会很好:
foreach ((int collectionId, List<Entry> entries) in allEntries)
Run Code Online (Sandbox Code Playgroud)
我已经添加System.ValueTuple到项目中了.
能够像这样写它会比这种传统风格好得多:
foreach (var kvp in allEntries)
{
int collectionId = kvp.Key;
List<Entry> entries = kvp.Value;
}
Run Code Online (Sandbox Code Playgroud) 我有一个使用SystemJS的SPA(在Aurelia/TypeScript中,但这无关紧要).让我们说它运行于http://spa:5000/app.
它有时会像waterservice/external.js外部URL一样按需加载JavaScript模块http://otherhost:5002/fetchmodule?moduleId=waterservice.external.js.我用SystemJS.import(url)它做这个,它工作正常.
但是当这个外部模块想要导入另一个模块时,import { OtherClass } from './other-class';这个(可理解的)不起作用.当它被SPA加载时,它会看到http://spa:5000/app/other-class.js.在这种情况下,我必须拦截路径/位置以将其重定向到http://otherhost:5002/fetchmodule?moduleId=other-class.js.
注意:waterservice/external.ts作品查找的Typescript编译因为typescript编译器可以./other-class.ts轻松找到.显然我不能使用绝对URL进行导入.
如何拦截我使用SystemJS导入的模块内的模块加载?
我已经测试过的一种方法是在SystemJS配置中添加映射.如果我像它一样导入它import { OtherClass } from 'other-class';并添加一个像"other-class": "http://otherhost:5002/fetchmodule?moduleId=other-class"它一样的映射.但是如果这种方法很好,我怎样才能在运行时动态添加映射?
其他方法,如通用加载URL拦截也是受欢迎的.
更新
我尝试拦截SystemJS,就像这样的artem
var systemLoader = SystemJS;
var defaultNormalize = systemLoader.normalize;
systemLoader.normalize = function(name, parentName) {
console.error("Intercepting", name, parentName);
return defaultNormalize(name, parentName);
}
Run Code Online (Sandbox Code Playgroud)
这通常不会改变任何东西,只会产生一些控制台输出以查看正在发生的事情.不幸的是,这似乎改变了一些东西,因为我得到一个错误未捕获(在承诺中)TypeError:this.has不是一个函数内部system.js.
然后我尝试添加映射SystemJS.config({map: ...});.令人惊讶的是,这个函数是增量的,所以当我调用它时,它不会松开已经提供的映射.所以我可以这样做:
System.config({map: {
"other-class": `http://otherhost:5002/fetchModule?moduleId=other-class.js`
}});
Run Code Online (Sandbox Code Playgroud)
这不适用于相对路径(以 …
我设计了一个可重复使用的用户控件.它包含UserControl.InputBindings.这很简单,因为它只包含一个标签和一个按钮(和新的属性等)
当我在窗口中使用控件时效果很好.但是密钥绑定仅在集中时才起作用.当一个控件具有对alt + f8的绑定时,此快捷方式仅在聚焦时才有效.当具有自己的绑定的另一个被聚焦时,那个可以工作但不再是alt + f8.当没有控件具有焦点时,没有任何作用.
如何实现我的usercontrol定义窗口范围的键绑定?
特别是遵循MVVM设计模式(Caliburn.Micro使用),但任何帮助表示赞赏.
用户控件的XAML:
<UserControl x:Class="MyApp.UI.Controls.FunctionButton"
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"
xmlns:local="clr-namespace:MyApp.UI.Controls"
xmlns:cm="http://www.caliburnproject.org"
x:Name="Root"
Focusable="True"
mc:Ignorable="d"
d:DesignHeight="60" d:DesignWidth="120">
<UserControl.Resources>
...
</UserControl.Resources>
<UserControl.InputBindings>
<KeyBinding Key="{Binding ElementName=Root, Path=FunctionKey}" Modifiers="{Binding ElementName=Root, Path=KeyModifiers}" Command="{Binding ElementName=Root, Path=ExecuteCommand}" />
</UserControl.InputBindings>
<DockPanel LastChildFill="True">
<TextBlock DockPanel.Dock="Top" Text="{Binding ElementName=Root, Path=HotkeyText}" />
<Button DockPanel.Dock="Bottom" Content="{Binding ElementName=Root, Path=Caption}" cm:Message.Attach="[Event Click] = [Action ExecuteButtonCommand($executionContext)]" cm:Action.TargetWithoutContext="{Binding ElementName=Root}" />
</DockPanel>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
用法示例:
<Grid>
<c:FunctionButton Width="75" Height="75" Margin="10,10,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" FunctionKey="F1" ShiftModifier="True" cm:Message.Attach="[Event Execute] = [Action Button1Execute]" />
<c:FunctionButton Width="75" Height="75" …Run Code Online (Sandbox Code Playgroud) 我使用Newtonsoft JSON来序列化/反序列化我的对象.其中一个包含一个带有受保护的setter的数组,因为构造函数构建了数组本身,只有成员被操纵.
这可以没有问题地序列化,但是当涉及反序列化时,它被忽略,因为它不是公共的.我尝试了一个自定义转换器,它也没有被调用,因为它不公开.
这是一个最小化的例子:
public static class TestCoordsDeserialization
{
private class Coords
{
public Double X { get; set; }
public Double Y { get; set; }
public Double Z { get; set; }
public Double A { get; set; }
}
private class Engine
{
public string Text { get; set; }
public int Id { get; set; }
public Coords[] Outs { get; protected set; }
public Engine()
{
this.Outs = new Coords[3];
for (int i = 0; …Run Code Online (Sandbox Code Playgroud) 我创建了一个C++/CLI(混合)程序集,它有一个围绕某些非托管C++代码的托管包装类.托管部分以.NET 4.6.1为目标,我得到了一个entry.cpp只有这一行的文件来做到这一点:
[assembly:System::Runtime::Versioning::TargetFrameworkAttribute(L".NETFramework,Version=v4.6.1", FrameworkDisplayName = L".NET Framework 4.6.1")];
Run Code Online (Sandbox Code Playgroud)
当我现在在.NET 4.6.1项目中手动包含已编译的程序集时,我可以按预期使用托管类.
该项目可以构建四种方式:x86或x64作为调试或发布版本.它没有托管依赖项.
现在我想要一个(或者如果需要多个)NuGet包,我可以上传到我的feed并在我想要的每个.NET 4.6.1兼容项目中轻松使用包装器组件.我该如何实现这一目标?
到目前为止我尝试了两种方法:
首先,我创建了一个.autopkg文件,根据这篇博文文章提供本机DLL的方式.该files文件的部分如下所示:
files {
// include: { *.h };
[x86,v120,release] {
symbols: { ..\Release\*.pdb; }
bin: { ..\Release\*.dll; }
};
[x86,v120,debug] {
symbols: { ..\Debug\*.pdb; }
bin: { ..\Debug\*.dll; }
};
};
Run Code Online (Sandbox Code Playgroud)
此过程会生成三个.nupkg文件,我可以将其上传到我的Feed.但是当我尝试将该软件包安装到.NET 4.6.1项目时,我收到以下错误消息:
无法安装包'MyCppCliWrapper.redist 1.0.0.2'.您正在尝试将此软件包安装到以".NETFramework,Version = v4.6.1"为目标的项目中,但该软件包不包含任何与该框架兼容的程序集引用或内容文件.有关更多信息,请与软件包作者联系.
所以我重新考虑是否应该使用托管程序集的方式来创建,.nupkg因为程序集有一个我想从托管代码中使用的托管类.我创建了一个.nuspec(使用nuget spec)并提供了元数据.然后我尝试像这样创建我的包:
nuget pack …Run Code Online (Sandbox Code Playgroud) 我有一个复杂的应用程序,可以作为Windows服务和控制台应用程序运行.
我主要使用控制台启动进行调试.当我在控制台按Ctrl + C时,应用程序立即停止(进程结束).
当我将应用程序作为服务运行并选择停止它时,MMC立即说该服务已停止.但是,该过程仍在运行,大约需要一分钟才能停止.我花了很多时间没有问题,但我想让MMC像其他服务一样等待.目前,我可以在旧进程仍在运行时再次启动该服务,这会产生独占资源错误.MMC中的"重启"也不起作用,因为它不等待进程结束.
如何让我的进程等待或如何找出哪些线程/进程/方法花费时间?
使用marshal_cppstd.h和msclr::interop::marshal_as<>我可以编组托管字符串,std::string如下所示:
String^ managed = "test";
std::string unmanaged = marshal_as<std::string>(managed);
Run Code Online (Sandbox Code Playgroud)
现在,当managed我正在编写代码的类的成员时,我在执行此操作时出现错误:
std::string unmanaged = marshal_as<std::string>(this->managed);
Run Code Online (Sandbox Code Playgroud)
错误说:
没有重载函数"marshal_as"的实例与参数列表匹配
或者作为编译器错误C2665:
'msclr :: interop :: marshal_as':3个重载中没有一个可以转换所有参数类型
当我更改代码以使用辅助变量时,它可以工作:
String^ localManaged = this->managed;
std::string unmanabed = marshal_as<std::string>(localManaged);
Run Code Online (Sandbox Code Playgroud)
这里肯定有一些隐式投射,不是吗?为什么会发生这种情况以及如何使简单的单线程工作?
c# ×4
.net ×2
c++-cli ×2
wpf ×2
.net-4.5 ×1
android ×1
arrays ×1
asp.net-mvc ×1
c#-7.0 ×1
dictionary ×1
drawable ×1
ecmascript-6 ×1
inputbinding ×1
javascript ×1
json ×1
json.net ×1
mvvm ×1
nancy ×1
nuget ×1
owin ×1
self-hosting ×1
service ×1
shape ×1
systemjs ×1
tab-ordering ×1
valuetuple ×1
winforms ×1