如何将控件作为参数传递给委托
我需要为在后面的代码中创建的 ComboBox 设置 ComboBoxItem 的样式。到目前为止,这是我的代码,
ComboBox cbo1 = new ComboBox();
cbo1.IsTextSearchEnabled = true;
cbo1.IsEditable = true;
grid1.Children.Add(cbo1);
cbo1.Dispatcher.BeginInvoke(new StyleComboBoxItemDelegate(ref StyleComboBoxItem(cbo1), System.Windows.Threading.DispatcherPriority.Background);
public delegate void StyleComboBoxItemDelegate(ComboBox cbo_tostyle);
public void StyleComboBoxItem(ComboBox cbo_tostyle)
{
//code to style the comboboxitem;
}
我收到以下错误
1. A ref or out argument must be an assignable variable
2. Method name expected
请有人帮助我指出我做错了什么?
非常感谢
I am needing to style a ComboBoxItem for a ComboBox that is being created in code behind. Here's my code so far
ComboBox cbo1 = new ComboBox();
cbo1.IsTextSearchEnabled = true;
cbo1.IsEditable = true;
grid1.Children.Add(cbo1);
cbo1.Dispatcher.BeginInvoke(new StyleComboBoxItemDelegate(ref StyleComboBoxItem(cbo1), System.Windows.Threading.DispatcherPriority.Background);
public delegate void StyleComboBoxItemDelegate(ComboBox cbo_tostyle);
public void StyleComboBoxItem(ComboBox cbo_tostyle)
{
//code to style the comboboxitem;
}
I am getting the following errors
1. A ref or out argument must be an assignable variable
2. Method name expected
Please can someone help me in pointing as to what I am doing wrong?
Many Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用以下任一方法:
Try using either of these:
StyleComboBoxItem()
“返回”void,因此通过使用ref StyleComboBoxItem(...)
,您实际上是在尝试创建对 void 的引用。您可以:
StyleComboBoxItem()
返回它设置样式的 ComboBox,因此您仍然可以内联使用它不需要 ref 。
StyleComboBoxItem()
"returns" void, so by usingref StyleComboBoxItem(...)
you're actually trying to create a reference to void.You could either:
StyleComboBoxItem()
return the ComboBox it styled, so you can still use it inlineThe ref is not needed.