我想在WPF中为我的Listbox提供一个上下文菜单.我使用整个列表框的上下文菜单来完成它,但即使您没有单击某个项目,也可以通过richt-click来获取上下文菜单.
我在谷歌找到了一些东西,但这没有用.
我试过这样的事情:
<ListBox Margin="5" ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}">
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="{Binding Name}" Click="MenuItemName_Click"/>
<MenuItem Header="{Binding Capital}" Click="MenuItemCapital_Click"/>
<MenuItem Header="{Binding Population}" Click="MenuItemPopulation_Click"/>
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
我尝试使用像示例中的文本块,与其他教程中的其他元素一样,我厌倦了没有和许多其他东西 - 但没有任何效果.我的列表框项目没有上下文菜单:(
后来我尝试过这样的事:
<ListBox.ItemTemplate>
<DataTemplate>
<ListBoxItem>
<ListBoxItem.ContextMenu>
<ContextMenu>
<MenuItem/>
</ContextMenu>
</ListBoxItem.ContextMenu>
</ListBoxItem>
</DataTemplate>
</ListBox.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)
但它也没有用.
有人可以给我一个提示/工作示例:)?
谢谢
有没有办法用autofac返回null?如果我这样做,我会得到一个例外.
在某些情况下,我无法解析一个对象,应该返回null.
m_builder.Register < IMyObject > ((c, p) => {
//do something
if (...) {
//cant create/resolve object (error case)
return null;
} else {
return new IMyObject();
}
}).InstancePerHttpRequest();
Run Code Online (Sandbox Code Playgroud)
是否有使用autofac执行此操作的内置方法?
编辑:我想返回null.或者执行其他操作以通知用户创建不成功.如果我返回null,则抛出此异常:
DependencyResolutionException:
注册为创建"IMyObject"实例的委托返回null.
堆栈跟踪:
在Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext上下文,IEnumerable的1个参数) 在Autofac.Core.Resolving.InstanceLookup.b__0() 在Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(GUID ID,Func键1个参数) 在Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration注册,IEnumerable的1个参数) 在Autofac.ResolutionExtensions.TryResolveService(IComponentContext上下文中,服务服务,IEnumerable的1个参数) 在Autofac.ResolutionExtensions.Resolve [TService](IComponentContext上下文,IEnumerable` 1个参数) 在Autofac.ResolutionExtensions.Resolve [TService](IComponentContext上下文中,参数[]参数) 在RestApi.Controllers.MyApiController.CreateEntityContext()在C:...
1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable1 creator)
at Autofac.Core.Resolving.InstanceLookup.Execute() at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable1 parameters)
at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable1 parameters, Object& instance) at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable
嗨,我想将一些动态生成的内容上传到我的网络API.在客户端我使用HttpWebRequest.数据应该上传同步,我想写入流AFTER(!)我执行了HTTP请求.
(从服务器到客户端它确实工作正常,但从客户端到服务器我得到一些例外).
客户端实现如下:
HttpWebRequest httpWebRequest = HttpWebRequest.Create(myUrl) as HttpWebRequest;
httpWebRequest.Method = "POST";
httpWebRequest.Headers["Authorization"] = "Basic " + ... ;
httpWebRequest.PreAuthenticate = true;
httpWebRequest.SendChunked = true;
//httpWebRequest.AllowWriteStreamBuffering = false; //does not help...
httpWebRequest.ContentType = "application/octet-stream";
Stream st = httpWebRequest.GetRequestStream();
Task<WebResponse> response = httpWebRequest.GetResponseAsync();
// NOW: Write after GetResponse()
var b = Encoding.UTF8.GetBytes("Test1");
st.Write(b, 0, b.Length);
b = Encoding.UTF8.GetBytes("Test2");
st.Write(b, 0, b.Length);
b = Encoding.UTF8.GetBytes("Test3");
st.Write(b, 0, b.Length);
st.Close();
var x = response.Result;
Stream resultStream = x.GetResponseStream();
//do some output...
Run Code Online (Sandbox Code Playgroud)
我在stream.write()上得到异常(NotSupportedException:流不支持并发IO读或写操作.).
为什么我这里有例外.有时第一次写入worke而后期写入会抛出异常.在开始时,stream.CanWrite属性为true,但在第一次或第二次或第四次写入后,它变为false …
web api似乎只适用于标准用例.但我想做更复杂的路由,但找不到复杂路由的文档.如果我有更多的控制器,路由变得越来越复杂.
我可以使用依赖项定义几个可选参数吗?像这样:
/api/document/{par1}/{par2}
Run Code Online (Sandbox Code Playgroud)
par1和par2应该是可选的,但par2应仅在par1存在时匹配.
并且递归参数可能吗?
/api/documents/characteristics/{round/green/red-dots}
/api/documents/characteristics/{square/yellow}
/api/documents/characteristics/{square/yellow/flat}
/api/documents/characteristics/{square/yellow/flat/...}
Run Code Online (Sandbox Code Playgroud)
是否有关于web api路由的详细文档?微软教程太基础了...我需要有关路由的更多信息.
我有两个控制器和一些麻烦,因为两个路由非常相似,所以采取了错误的路线.我可以使用[Action] -Attribute作为解决方法,但这感觉不对......我还必须考虑路由的顺序.这是合乎逻辑的,但未提及.web api只适用于简单的休息api吗?
编辑: 我试过这个:
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{mandant}/documents/{id}",
defaults: new { controller = "documents", id = RouteParameter.Optional }
);
//routes.MapHttpRoute(
// name: "DefaultApiWithAction",
// routeTemplate: "api/{mandant}/documents/{id}/{action}",
// defaults: new { controller = "documents" }
// );
Run Code Online (Sandbox Code Playgroud)
我有两种方法:
[AcceptVerbs("get")]
public HttpResponseMessage Get(int id)
[ActionName("file")]
[AcceptVerbs("get")]
public HttpResponseMessage filedownload(int id)
Run Code Online (Sandbox Code Playgroud)
现在我遇到了问题,即使我注释掉第二条路线也触发了文件操作,并且由于多个动作而没有触发正常的获取特定文档方法...我尝试了[NoAction]属性但这不起作用..但是如果路由模板中没有动作,为什么会触发文件方法呢?(或者如果第二个路由处于活动状态,为什么如果url中没有动作,则不会触发正常的get-document方法....)我当前的解决方法是为所有其他方法设置default-action,但是这不是一个好的解决方案.
我正在搜索一个在ASP.NET MVC 4 Web Api中启用登录/跟踪的功能.在WCF中,您可以激活它正在执行的日志记录和WCF写入.然后,我可以打开转储并搜索错误.
我不想跟踪我的web api,而是记录框架正在做的事情.如果我使用消息处理程序跟踪/记录web api,如果在实现之前发生错误,我将得不到任何信息.
我有以下架构:
Client1(Browser-App) -> Server1 (WebAPI/IIS) -> Server2 (WebAPI/IIS)
Run Code Online (Sandbox Code Playgroud)
我将 ASP.NET 用于服务器端应用程序/api,并且用户应通过“Windows 集成身份验证”进行身份验证。
正如您所看到的,从 server1 到 server2 有第二个跃点。如果两个 WebAPI 不在同一服务器上,NTML 不支持第二个跃点。所以我配置了一个AD域来支持“kerberos”。
现在它可以与第二个跃点一起使用。我的测试 WebAPI 输出用户的身份,如下所示:
server1: test.domain/user1
server2: test.domain/user1
Run Code Online (Sandbox Code Playgroud)
但是,如果我更改 Client1 上的登录用户并执行与“otherUser2”相同的请求,则只有第一跳获得正确的身份:
server1: test.domain/otherUser2
server2: test.domain/user1
Run Code Online (Sandbox Code Playgroud)
在第二跳上,显示第一个请求的旧用户。我测试了多种场景:如果以下请求来自另一个 Windows 用户的另一个客户端,则行为相同...
看起来第一个请求的Windows身份缓存在server2上...这对我来说是一个大问题,我认为这不应该是可能的...如果请求在错误的用户中执行,这是一个很大的安全漏洞语境!
这是一个已知问题吗?我做错什么了吗?有没有解决办法或者更好的配置?
在第一个 ASP.NET WebAPI 上,我使用如下模拟:
WindowsIdentity identity = (WindowsIdentity)HttpContext.Current.User.Identity;
using (var wic = identity.Impersonate())
{
try
{
WebClient c = new WebClient
{
UseDefaultCredentials = true
};
Run Code Online (Sandbox Code Playgroud)
c# asp.net kerberos windows-authentication kerberos-delegation
我想聊天内嵌图片.richtextbox很好,因为我可以在其中放置图像,但我想将文本/图像分开发送.-first:发送文本(并在文本中放置图像占位符).-second:发送图像并用占位符替换它.
为此,我需要删除richtextbox中的所有图像(并将它们分开发送).但是我怎么能找到这些图像呢?
顺便说一下:是否可以根据richtextbox的宽度重新缩放图像?
谢谢 :)
我有这个变量(int和double-array)
.H-文件
@interface MyCLass : NSObject
{
int myInt;
double paramStack[100];
}
@property (nonatomic, assign) int myInt;
//@property (nonatomic, assign) double paramStack; //<- ?
Run Code Online (Sandbox Code Playgroud)
.M-文件
@synthesise myInt;
//@synthesize paramStack; //<- ?
Run Code Online (Sandbox Code Playgroud)
我希望int和double-array-variable可以通过属性从其他类访问.对于int-var.它看起来很好,但是数组会在.m-file(@synthsize)和h.file(@property(nonatomic,assign)double paramStack)中抛出错误.
我如何定义"@property(nonatomic,assign)double paramStack;" 作为一个双阵列?
谢谢
早些时候我看到了这个:
.InstancePerApiRequest();
Run Code Online (Sandbox Code Playgroud)
现在我只有这个:
.InstancePerHttpRequest();
Run Code Online (Sandbox Code Playgroud)
autofac是否删除了API范围?我有参考Autofac.Integration.WebApi但这个扩展名不可用.InstancePerHttpRequest和InstancePerApiRequest有什么区别?
我有这条路线:
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}/{myparam}",
defaults: new { id = RouteParameter.Optional, myparam = RouteParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
'id'应该是可选的,'myparam'应该是可选的,但如果'myparam'被设置,'id'不能是可选的.我该如何配置?
c# ×5
autofac ×2
wpf ×2
arrays ×1
asp.net ×1
asynchronous ×1
chunked ×1
contextmenu ×1
diagnostics ×1
double ×1
image ×1
int ×1
kerberos ×1
listbox ×1
listboxitem ×1
logging ×1
objective-c ×1
richtextbox ×1
routing ×1
scope ×1
stream ×1
url-template ×1