我正在使用System.Net.Http,我在网上找到了几个例子.我设法创建此代码以发出POST请求:
public static string POST(string resource, string token)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(baseUri);
client.DefaultRequestHeaders.Add("token", token);
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("", "")
});
var result = client.PostAsync("", content).Result;
string resultContent = result.Content.ReadAsStringAsync().Result;
return resultContent;
}
}
Run Code Online (Sandbox Code Playgroud)
一切正常.但是假设我想要将第三个参数传递给POST方法,这个参数叫做data.数据参数是这样的对象:
object data = new
{
name = "Foo",
category = "article"
};
Run Code Online (Sandbox Code Playgroud)
如何在不创建的情况下做到这一点KeyValuePair?我的php RestAPI等待json输入,所以FormUrlEncodedContent应该raw正确发送json.但我怎么能这样做Microsoft.Net.Http呢?谢谢.
我正在使用 Framework Mahapps.Metro,在禁用十进制值的文档中有一个属性:HasDecimals,我将其设置为False但如果我输入:5.01控件允许我插入此值。也许这是一个错误?
<Controls:NumericUpDown x:Name="Timer" Minimum="5" Value="15" HasDecimals="False" Maximum="1440" />
Run Code Online (Sandbox Code Playgroud)
我还想问如何禁用科学值,因此只接受整数。可以通过 XAML 做到这一点吗?或者我怎样才能在代码后面做到这一点?
我有以下内容Combobox:
<ComboBox x:Name="Colors" FontSize="20">
<ComboBoxItem Background="#46d6db" Tag="#46d6db">Blue</ComboBoxItem>
<ComboBoxItem Background="#FDB75B" Tag="#FDB75B">Orange</ComboBoxItem>
<ComboBoxItem Background="#51B749" Tag="#51B749">Green</ComboBoxItem>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)
现在您可以看到我有三个具有特定Tag属性的 ComboBoxItem。这里的标签属性就是颜色的值。
我需要知道的是:如何通过 Tag 属性获取特定 ComboBoxItem 的索引?
我将尝试更清楚地解释它:假设我有一个名为colorvalue 的字符串#FDB75B,现在我需要找到具有相同值的 ComboBox 项,并特别Tag获取 this 的位置。ComboBoxItem
string color = "#FDB75B";
//In this way I get the Tag property of the selected item
((ComboBoxItem)Colors.SelectedItem).Tag.ToString();
Run Code Online (Sandbox Code Playgroud)
现在我需要做相反的情况,找到ComboBoxItem带有标签的索引#FDB75B,并自动选择它,如下:
Colors.SelectedIndex = "element found";
Run Code Online (Sandbox Code Playgroud)
这可能吗?
我正在使用MahApp,我创建了以下内容TabControl:
<TabControl TabStripPlacement="Left" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0">
<TabItem>
<TabItem.Header>
<Image Source="Images/Icon.png"></Image>
</TabItem.Header>
<TabItem.Content>
<Grid>
<Controls:Scheduler x:Name="Scheduler"/>
</Grid>
</TabItem.Content>
</TabItem>
</TabControl>
Run Code Online (Sandbox Code Playgroud)
我该如何处理该MouseOver事件并更改颜色?实际上,如果我将鼠标移到 TabItem 上,用户不知道 TabItem 是否可单击。提前致谢。
我正在使用UndhandledException提供的AppDomain,我所做的基本上是这样的:
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;
}
static void UnhandledExceptionTrapper(object sender, UnhandledExceptionEventArgs e)
{
e.ExceptionObject.Message? <- there is no message
Console.WriteLine(e.ExceptionObject.ToString());
Console.WriteLine("Press a key for exit.");
Console.ReadLine();
Environment.Exit(1);
}
Run Code Online (Sandbox Code Playgroud)
你怎么看我无法访问message属性,但是如果我设置了一个断点我可以在e变量上看到Message属性,为什么我不能使用它?
假设我有一个名为的类Bot,如下所示:
class Bot
{
}
Run Code Online (Sandbox Code Playgroud)
现在有另一个类具有该类的所有功能Bot,此类称为Tool:
class Tool
{
//some method
}
Run Code Online (Sandbox Code Playgroud)
现在Bot是唯一必须继承方法的类Tool.我怎样才能像where操作员一样约束这个?像这样的东西:
class Tool where T = Bot ?
Run Code Online (Sandbox Code Playgroud)
我不知道是否清楚,但我希望只有Bot类可以继承方法Tool,有可能做到这一点吗?对于基本的解释感到抱歉.
提前致谢.