清单Box的数据模板由XamlReader动态确定。 Load。 我正在通过利用视觉TreeHelper获得Box物体来检查事件。 GetChild. 这一事件没有发射
《刑法》
public void SetListBox()
{
lstBox.ItemTemplate =
XamlReader.Load(@"<DataTemplate xmlns= http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x= http://schemas.microsoft.com/winfx/2006/xaml x:Name=""DropDownTemplate""><Grid x:Name= RootElement ><CheckBox x:Name= ChkList Content= {Binding " + TextContent + "} IsChecked= {Binding " + BindValue + ", Mode=TwoWay} /></Grid></DataTemplate>") as DataTemplate;
CheckBox chkList = (CheckBox)GetChildObject((DependencyObject)_lstBox.ItemTemplate.LoadContent(), "ChkList");
chkList.Checked += delegate { SetSelectedItemText(); };
}
public CheckBox GetChildObject(DependencyObject obj, string name)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
{
DependencyObject c = VisualTreeHelper.GetChild(obj, i);
if (c.GetType().Equals(typeof(CheckBox)) && (String.IsNullOrEmpty(name) || ((FrameworkElement)c).Name == name))
{
return (CheckBox)c;
}
DependencyObject gc = GetChildObject(c, name);
if (gc != null)
return (CheckBox)gc;
}
return null;
}
如何处理检查活动? 请帮助