如果我的网格中有UserControl以下两个,如下所示:Label
<Grid x:Name="mainGrid">
<Label x:Name="labelTitle"/>
<Label x:Name="labelValue"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
我可以在类似以下内容中单独设置它们的样式吗ResourceDictionary:
<Style TargetType="{x:Type MyControl}">
<Style.Resources>
<Style TargetType="MyControl.mainGrid.labelTitle">
</Style>
<Style TargetType="MyControl.mainGrid.labelValue">
</Style>
</Style.Resources>
</Style>
Run Code Online (Sandbox Code Playgroud)
如果可能的话,我想在其中完成所有这些工作,而根本ResourceDictionary不需要接触。UserControl
我编写了一个 C# 程序,它使用命令行参数来打开和关闭防火墙。
Process proc = new Process();
string top = "netsh.exe";
proc.StartInfo.Arguments = "**Advfirewall set allprofiles state on**";
proc.StartInfo.FileName = top;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.WaitForExit();
// MessageBox.Show("Disable");
button1.Text = "Set On";
status = false;
Run Code Online (Sandbox Code Playgroud)
我还以管理员权限运行该应用程序。该应用程序会自动以管理员权限运行,但不会将防火墙状态设置为打开或关闭。
当我在 cmd(netsh) 中运行相同的命令时,防火墙会打开或关闭。
有谁知道为什么这不起作用?
我的格式如下DateTime.ToString:
ddMMy
Run Code Online (Sandbox Code Playgroud)
但是,此格式返回年份的两位数字的日期,16而不是6.请参阅以下代码示例:
DateTime dt = new DateTime(2016, 9, 12);
Console.WriteLine(dt.ToString("ddMMyy"));
Run Code Online (Sandbox Code Playgroud)
这显示:
120916
而不是预期的:
12096
为了使以下代码更复杂:
string date = "12096";
Console.WriteLine(DateTime.ParseExact(date, "ddMMy", System.Globalization.CultureInfo.CurrentCulture,
System.Globalization.DateTimeStyles.None).ToString("yyyyMMdd"));
Run Code Online (Sandbox Code Playgroud)
产生输出:
20060912
我可以传递一种格式来获取所需的输出,13096或者这是DateTime.ToString实现中的错误吗?
我有一个方法,使用它来汇总和输出它out.我的方法看起来像这样:
public void MyMethod(int page, string city, out int citySum)
{
citySum = 0;
for(int i = 0; i < 50; i++)
{
citySum++;
}
if(page < 15)
{
MyMethod(page + 1, city,out citySum);
}
}
Run Code Online (Sandbox Code Playgroud)
令我困惑的是我想要citySum总计.但是使用此配置,citySum在每个递归步骤变为零.如何保持值citySum并将其传递到下一个递归步骤?
我正在尝试做一个Crono.我试图使用以下代码创建一个双功能按钮(开始/停止):
private void buttonStartStop_Click(object sender, EventArgs e)
{
if (buttonStartStop.Text=="Start")
{
timerCrono.Enabled = true;
buttonStartStop.Text = "Stop";
buttonResetLap.Text = "Lap";
}
if (buttonStartStop.Text == "Stop")
{
timerCrono.Enabled = false;
textBoxLaps.Text += "(Lap " + laps + ")" + " " + min + ":" + sec + "," + decsec + "\r\n";
laps++;
buttonStartStop.Text = "Start";
buttonResetLap.Text = "Reset";
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我点击它时它似乎做了2个功能.
那么我能做些什么才能在一个按钮中完成2个独立的功能呢?
我正在努力弄清楚如何返回一个只包含一个或多个所需查询参数的项目列表.
我认为TrueForAll可能有效,但如果其中一个不存在则返回false.
var hasValidOptions = entity.clientcodes.TrueForAll(x => x.code == "B"
|| x.code == "C"
|| x.code == "E"
|| x.code == "G"))
Run Code Online (Sandbox Code Playgroud)
以下是我正在尝试做的一些例子(我只关注B,C,E和G):
A B E G- > false因为它包含A.B G- > true,因为它包含B和G.E- > true,因为它包含E.B C E G- > true,因为它包含B,C,E和G.我怎样才能做到这一点?
var str = "GB29NWBK60161331926819"
foreach (var item in str.ToCharArray())
{
Debug.WriteLine(str.IndexOf(item));
}
Run Code Online (Sandbox Code Playgroud)
给出输出
0 1 2 3 4 5 1 7 8 9 10 8 10 13 13 10 3 2 8 19 10 3
我在期待
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
是这个还是一个bug还是我的假设不正确?
如何从此替换以下字符串:
"Hello @app@username@, my name is @app@name@."
Run Code Online (Sandbox Code Playgroud)
至
"Hello <span>@app@username@</span>, my name is <span>@app@name@</span>."
Run Code Online (Sandbox Code Playgroud)
有大量的应用程序变量@app@variable@.