我必须通过 TextBox id 访问和更改某些 Word 文档的某些文本框的文本。例如,假设我在 word 文档中有一个名为 txtDate 的对象,我想将其内容更改为现在的日期,那么如何通过其 id 获取该对象?
如何将Text
的属性绑定TextBox
到FoundationHeight
代码隐藏中定义的 clr-property。
xaml
<TextBox Text="{Binding FoundationHeight}"/>
Run Code Online (Sandbox Code Playgroud)
C#
public double FoundationHeight { get; set; }
public AssignColumnPropertiesWindow()
{
InitializeComponent();
FoundationHeight = 60;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Galasoft MVVMLight的RelayCommand执行RelayCommand(在我的CodeBehind中).
MainPage.xaml.cs中
public MainPage()
{
InitializeComponent();
DataContext = this;
MyCommand = new RelayCommand(Methode);
}
#region Commands
public RelayCommand MyCommand { get; private set; }
#endregion
private void Methode()
{
int i = 1;
}
Run Code Online (Sandbox Code Playgroud)
MainPage.xaml中:
<Button Command="{Binding MyCommand}"/>
Run Code Online (Sandbox Code Playgroud)
不幸的是,命令没有触发/该方法没有被调用.像ImageSource这样的其他绑定元素......工作正常.
我有上下文菜单的datagrid.它以编程方式初始化:
contextMenu = new ContextMenu();
foreach (var col in this.Columns)
{
var checkBox = new MenuItem()
{
Header = col.Header
};
Binding myBinding = new Binding("Visibility");
myBinding.Mode = BindingMode.TwoWay;
myBinding.Converter = new IsCheckedToVisibilityConverter();
checkBox.DataContext = col;
checkBox.SetBinding(MenuItem.IsCheckedProperty, myBinding);
checkBox.Click += checkBox_Click;
checkBox.Checked += checkBox_Checked;
checkBox.Unchecked += checkBox_Unchecked;
contextMenu.Items.Add(checkBox);
}
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但我想在检查\取消选中菜单项后保持打开上下文菜单.有任何想法吗 ?
我有几个我想在托盘图标中显示的数字...为此我需要将这些数字转换为图标或任何位图图像....需要帮助是他们在 wpf c# 中的任何类或属性来这样做.. 任何方法……我试过的方法不起作用……
Font fnt = new Font("Tahoma", 8 );
fntheight += fnt.Height;
int maxheight = 0;
if (state == true)
maxheight = height + fntheight + fntheight;
else
maxheight = height + fntheight;
Graphics grf = Graphics.FromImage(myimg);
Image newimg = new System.Drawing.Bitmap(width, maxheight);
Graphics newgrf = Graphics.FromImage(newimg);
newgrf.FillRectangle(Brushes.White, 0, 0, width, height);
Run Code Online (Sandbox Code Playgroud)
但是这段代码在当前的 wpf c# .net 4+ 中不起作用
我有一个带有一些 DataGridTextColumn 的 DataGrid,如下所示:
<DataGrid x:Name="DonneesBrutes" IsReadOnly="True" ItemsSource="{Binding Path=ResultatCollectionGrande}" Margin="10,65,0,0" AutoGenerateColumns="False" EnableRowVirtualization="True" RowDetailsVisibilityMode="VisibleWhenSelected">
<DataGrid.Columns>
<DataGridTextColumn x:Name="PrisEnCompte" Binding="{Binding Path=Flag}" Header="Pris En Compte"></DataGridTextColumn>
<DataGridTextColumn x:Name="PMRQ" Width="*" Binding="{Binding Path=Pmid}" Header="PMID"></DataGridTextColumn>
<DataGridTextColumn x:Name="Ligne" Width="40" Binding="{Binding Path=Ligne}" Header="Ligne" IsReadOnly="True"></DataGridTextColumn>
<DataGridTextColumn x:Name="LibellePMRQ" Width="*" Binding="{Binding Path=LibellePmrq}" Header="Libellé PMRQ">
<DataGridTextColumn.HeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self},
Path=Column.(ToolTipService.ToolTip)}"/>
</Style>
</DataGridTextColumn.HeaderStyle>
</DataGridTextColumn>
<DataGridTextColumn x:Name="OTM" Width="*" Binding="{Binding Path=Otm}" Header="OTM"></DataGridTextColumn>
<DataGridTextColumn x:Name="TOTM" Width="50" Binding="{Binding Path=Totm}" Header="TOTM"></DataGridTextColumn>
<DataGridTextColumn x:Name="LibelleTOTM" Width="*" Binding="{Binding Path=LibelleTotm}" Header="Libellé TOTM">
<DataGridTextColumn.HeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self}, …
Run Code Online (Sandbox Code Playgroud) 目前使用以下代码收到错误,我不知道如何修复它!
这是错误:
Cannot assign to 'Add' because it is a 'method group'
这是我的App.xaml.cs:
public partial class App : Application
{
//Public list of users and form can access
List<User> LoggedUsers = new List<User>();
//First startup of the application
public void Application_Startup(object sender, StartupEventArgs e)
{
//First startup, display the login form
LoginWindow FirstLogin = new LoginWindow();
FirstLogin.ShowDialog();
//If the login form was closed properly, handle the user
if (FirstLogin.DialogResult == true)
{
//Add the user to the list of logged …
Run Code Online (Sandbox Code Playgroud) 我有一个类库项目,磁盘是140 KB.是否可以通过添加垃圾字节来增加程序集文件大小?
例如:
private byte[] junk = new byte[1500];
Run Code Online (Sandbox Code Playgroud)
将在内存中分配1500个字节,但我希望它们在任何PE模块部分(如.data部分)中保留.
我知道C#可以与MSIL一起使用,但是有没有选择来保存物理内存?
为什么我需要这个?好吧,客户要求我模仿他从以前的开发人员那里获得的功能和他可以找到的每个细节的库,其中包括文件大小,名称,版本等.我向他解释说,任何有正当知识的人都会发现库是不是原来的,但他坚持要在每一个细节上都配上它.
我知道他为什么需要这个,但那是出于主题.
我试图将参数从我的程序传递到EXEC格式的存储过程.以下是我的代码
public void button1_Click(object sender, EventArgs e)
{
frm = new FrmLogin();
OleDbConnection conn = new OleDbConnection("File Name=E:\\Vivek\\License Manager\\License Manager\\login.udl");
try
{
conn.Open();
string user = username.Text;
string pass = password.Text;
string query = "EXEC dbo.checkuser"' + username.Text'" + " " + "'password.Text'"";
OleDbCommand cmd = new OleDbCommand(query,conn);
cmd.ExecuteNonQuery();
// Retrieve the return value
string result = query.ToString();
MessageBox.Show(result);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
conn.Close();
}
Run Code Online (Sandbox Code Playgroud)
我应该在string query =""中写什么?,我试图将用户名和密码作为参数传递给存储过程,一旦查询执行并返回结果,我将把它存储在另一个名为result.Am的变量中.正确的方式?我是C#的新手
请建议,
谢谢
我有这个案子:
我从这样的列表中创建一个数组:
String[] parameters = stringParametersToSearch.Split(' ');
Run Code Online (Sandbox Code Playgroud)
参数的数量可以在1到n之间变化,我必须在描述字段中搜索包含所有参数出现的对象
List<LookUpObject> result =
components.Where(o => o.LongDescription.Contains(parameters[0])).ToList<LookUpObject>();
Run Code Online (Sandbox Code Playgroud)
如果参数是1这样做,但如果它们有两个或更多?
目前为了解决这种情况,我使用一个IF,在其中我为多达五个参数(最多的实际情况)的情况构建LINQ表达式.
我可以使用LINQ动态解决这种情况吗?
fun main(args: Array<String>) {
try {
var sum: Long = 0
val n: Int = readLine()!!.toInt()
for (i in 0..(n - 1)) {
var input: Long?
input = readLine()!!.toLong()
sum += input
}
println(sum)
} catch (ex: Exception) {
println(ex.message)
}
}
Run Code Online (Sandbox Code Playgroud)
我想把数据类型Long Long替换为Long.那么如何定义Long Long数据类型呢?
经常使用LINQ来过滤对象数组
我运行了一个产生相同结果的测试表达式,但是在不同的时间,我想知道这种行为的原因.
public long testTimeOperetionWHERE()
{
Object[] list = opCoIn.getList();
System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
int i = 0;
while (i<20000)
{
var result = list.Where(o => o.Id>0)
.Where(o => o.Import>0)
.Where(o => o.OrderConfirm==o.NumberConfirm)
.Where(o => o.IdActiveCustomer>100 );
i++;
}
long e = sw.ElapsedMilliseconds;
return e;
}
Run Code Online (Sandbox Code Playgroud)
时间成本结果总是在90-80之间变化
在这种情况下
public long testTimeOperetionAND()
{
Object[] list = opCoIn.getList();
System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
int i = 0;
while (i < 20000)
{
var result = list.Where(o => o.Id > 0
&& o.Import > …
Run Code Online (Sandbox Code Playgroud) c# ×11
wpf ×6
.net ×3
xaml ×3
linq ×2
binding ×1
contextmenu ×1
datagrid ×1
dll ×1
docker ×1
dockerhub ×1
kotlin ×1
ms-word ×1
relaycommand ×1
repository ×1
sql ×1
sql-server ×1