I have a loaded event of combobox placed in each datagrid row.Event is as following.
我在每个数据网格行中放置了一个加载的组合框事件。事件如下。
private void show(object sender, RoutedEventArgs e)
{
ComboBox cmb = null;
if (sender is ComboBox)
{
cmb = (sender as ComboBox);
}
for (var vis = sender as Visual; vis != null; vis = VisualTreeHelper.GetParent(vis) as Visual)
if (vis is DataGridRow)
{
var row = (DataGridRow)vis;
break;
}
cmb.items.add("1","2","3");
}
Now I want to call it at winload or any button event as method. how it is possible.
现在我想在winload或任何按钮事件中调用它作为方法。怎么可能。
1 个解决方案
#1
0
I am sorry, but what you're saying is not possible. You cannot find a combobox loaded event from somewhere, since it is not under your control.
对不起,但你所说的是不可能的。你无法从某个地方找到一个组合框加载的事件,因为它不受你的控制。
It is fired internally when the combobox is loaded. Hence you get the sender
as combobox.
加载组合框时会在内部触发。因此,您将发件人视为组合框。
If your purpose is simply adding values to the combobox consider binding the data template of your data grid to some source and bind the combobox source to some collection. Doing that will add the items initially to the combobox while the application is loaded and you could change the values accordingly while the application is running by changing the bound sources of combobox in the datatemplate.
如果您的目的只是向组合框添加值,请考虑将数据网格的数据模板绑定到某个源,并将组合框源绑定到某个集合。这样做会在加载应用程序时将项目最初添加到组合框中,您可以在应用程序运行时通过更改datatemplate中组合框的绑定源来相应地更改值。
#1
0
I am sorry, but what you're saying is not possible. You cannot find a combobox loaded event from somewhere, since it is not under your control.
对不起,但你所说的是不可能的。你无法从某个地方找到一个组合框加载的事件,因为它不受你的控制。
It is fired internally when the combobox is loaded. Hence you get the sender
as combobox.
加载组合框时会在内部触发。因此,您将发件人视为组合框。
If your purpose is simply adding values to the combobox consider binding the data template of your data grid to some source and bind the combobox source to some collection. Doing that will add the items initially to the combobox while the application is loaded and you could change the values accordingly while the application is running by changing the bound sources of combobox in the datatemplate.
如果您的目的只是向组合框添加值,请考虑将数据网格的数据模板绑定到某个源,并将组合框源绑定到某个集合。这样做会在加载应用程序时将项目最初添加到组合框中,您可以在应用程序运行时通过更改datatemplate中组合框的绑定源来相应地更改值。