考虑这个Windows窗体代码(可以编写类似的WPF模拟代码):
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void TraceThreadInfo([CallerMemberName]string callerName = null)
{
Trace.WriteLine($"{callerName} is running on UI thread: {!this.InvokeRequired}");
}
private void DoCpuBoundWork([CallerMemberName]string callerName = null)
{
TraceThreadInfo(callerName);
for (var i = 0; i < 1000000000; i++)
{
// do some work here
}
}
private async Task Foo()
{
DoCpuBoundWork();
await Bar();
}
private async Task Bar()
{
DoCpuBoundWork();
await Boo();
}
private async Task Boo()
{
DoCpuBoundWork();
// e.g., saving …Run Code Online (Sandbox Code Playgroud) 我想创建一个自定义工具提示,具有不同的样式,以便当我单击控件(例如标签或用户控件)时,它会出现.
类似于Google在Google地图中为坐标所做的事情.
我试图创建一个用户控件,并在用户点击标签时显示它,但它不能正常工作.
这是WinForms!
我附上了我想要的照片.先感谢您!

默认情况下,哪个.net框架将全新安装2008 R2?frameowkr 2.0或3.5或没有.如果我需要手动启用3.5意味着默认情况下已经安装了所有内容,我需要启用它还是需要安装?
我有boolean我的类属性.我想将它作为参数传递给一些期望Func的函数.有没有办法进行转换?或者我应该创建一个返回bool而不是属性的函数?
我有许多包含长列表的枚举,这些列表会不时发生变化
public MyEnumType MyEnum
{
None = 0,
Option1 = 1,
Option2 = 2,
etc..
}
Run Code Online (Sandbox Code Playgroud)
当他们改变时,我需要重新编号索引,因为在现有选项之间总是有新的选项.
问题是,如果我删除索引,枚举总是会从上到下尊重订单吗?
public MyEnumType MyEnum
{
None,
Option1,
Option2,
etc..
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
也许是一个微不足道的问题,但我正在画一个空白.
我有类似的东西:
public class Foo
{
private string _variableValue;
public string VariableValue
{
get
{
return _variableValue;
}
set
{
if (value == _variableValue) return;
_variableValue = value;
}
}
public int Precision { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
基本上,VariableValue持有双倍价值.我存储了一个小数精度数Precision.我怎样才能VariableValue Get返回自己但格式化的Precision小数位?
示例: VariableValue是"10.12345",Precision是2:
VariableValue应该是10.12
例子(2):VariableValue是"10",Precision是5:
VariableValue应该是10.00000
我有这个简单的UserControl:
<UserControl x:Class="WPFTreeViewEditing.UserControl1"
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">
<Grid>
<TextBlock Text="Hello, world!" KeyDown="TextBlock_KeyDown" />
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
我想处理 TextBlock.KeyDown 事件。因此,我在代码隐藏中添加了一个事件处理程序:
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private void TextBlock_KeyDown(object sender, KeyEventArgs e)
{
MessageBox.Show("Key up!");
}
}
Run Code Online (Sandbox Code Playgroud)
但它不着火。怎么了?
更新。
PreviewKeyDown也不火。
这UserControl用于HierarchicalDataTemplate当时:
<Window x:Class="WPFTreeViewEditing.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFTreeViewEditing"
Title="MainWindow" Height="265" Width="419">
<Grid>
<TreeView ItemsSource="{Binding}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:ViewModel}" ItemsSource="{Binding Items}">
<local:UserControl1 />
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud) 我创建了一个计算器,该计算器具有带数字的按钮和用于基本操作(+,-,...)的运算符,只想过滤带数字的按钮以检测单击数字的时间(介于0到9之间)。我也把新的eventhadler转换成按钮发送者。
我想知道什么是用数字过滤按钮的好方法(使用linq),到目前为止我尝试了什么
if(btn.Text == btn.Text.Contains(x => x >= '0' && x <= '9'))
MessageBox.Show("number " + btn.Text + " is pressed!");
Run Code Online (Sandbox Code Playgroud)
如何使上层代码可行?
我使用此代码在listbox1中插入数据:
if (!IsPostBack)
{
DataTable dt = new DataTable();
string query = "SELECT * FROM [Qualification]";
SqlDataAdapter objda = new SqlDataAdapter(query, conn);
//conn.Open();
objda.Fill(dt);
if (dt.Rows.Count > 0)
{
ListBox1.DataSource = dt;
ListBox1.DataTextField = "QDesc";
ListBox1.DataValueField = "QID";
ListBox1.DataBind();
}
}
Run Code Online (Sandbox Code Playgroud)
这些项目listbox2按钮点击进入
按钮点击代码是:
protected void Button1_Click1(object sender, EventArgs e)
{
string strItemText = "";
string strItemValue = "";
foreach (ListItem listItem in ListBox1.Items)
{
if (listItem.Selected == true)
{
strItemValue += listItem.Text;
}
}
ListBox2.Items.Add(strItemText+""+ strItemValue);
ListBox1.Items.Remove(ListBox1.SelectedItem);
} …Run Code Online (Sandbox Code Playgroud)