문제

나는 프로그램을하려고한다 ListBoxItem Selected 동적이 필요하기 때문에 코드 이벤트입니다 ListBoxItems. 나는 이것을 WPF로 코딩하고있다. 다음 XAML은 훌륭하게 작동한다.

<ListBoxItem Tag="cPage_Mod_Modules" Selected="ListBoxItem_Selected">
    <StackPanel Orientation="Horizontal">
        <TextBlock Style="{StaticResource sColor01}" Text="» " />
        <TextBlock Text="Moduler" VerticalAlignment="Center" Focusable="True" />
    </StackPanel>
</ListBoxItem>

그만큼 Selected="ListBoxItem_Selected" 잘 작동합니다.

그러나 내가 만들려고 할 때 ListBoxItem 코드에서는 작동하지 않습니다. 내 코드는 다음과 같습니다.

IList<ListBoxItem> lbi = new List<ListBoxItem>();
ListBoxItem itemBox = new ListBoxItem();
itemBox.Tag = "cPage_Assignment_Overview";
itemBox.Selected += new EventHandler(ListBoxItem_Selected(this, null));
lbTask.Items.Add(itemBox);

나는 단지 행사로 향하고 싶다 ListBoxItem_Selected(object sender, RoutedEventArgs e) 누군가 항목을 선택할 때.

도움이 되었습니까?

해결책

이벤트를 연결하는 방법을 의미합니까? 이를 수행해야합니다 (함수 서명이 이벤트 핸들러 서명과 호환된다고 가정).

itemBox.Selected += ListBoxItem_Selected;

다른 팁

변경해보십시오

itemBox.Selected += new EventHandler(ListBoxItem_Selected(this, null));

에게

itemBox.Selected += ListBoxItem_Selected;

귀하의 listboxitem_selected가 다음과 같이 선언되었다고 가정합니다

 public void ListBoxItem_Selected(object sender,RoutedEventArgs e)
 {

 }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top