ListBox의 데이터 형식은 XamlReader.Load에 의해 동적으로 설정됩니다. VisualTreeHelper.GetChild를 사용하여 CheckBox 객체를 가져 와서 Checked 이벤트를 구독하고 있습니다. 이 이벤트는Silverlight 3.0 사용자 지정 ListBox DataTemplate에 체크 상자가있는 체크 이벤트가 발생하지 않습니다.
에게코드 조각 체크 이벤트를 처리하는 방법
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;
}
을 해고되지 않는 이유는 무엇입니까? 도와주세요
답장을 보내 주셔서 감사에 대한 문제를 해결 아래 코드
을 추가했다. 그러나 체크 된 이벤트를 어떻게 처리 할 수 있습니까? – Bhaskar