2012-03-20 2 views
0

에 등록 된 모든 이벤트는 내가 목록보기가 관찰 컬렉션에 바인더 제본되어화재 특정 이벤트 핸들러

<ListView Name="listView2"> 
     <ListView.View> 
      <GridView> 
       <!-- First Column --> 
       <GridViewColumn Width="105" Header="ID"> 
        <GridViewColumn.CellTemplate> 
         <DataTemplate>    
          <StackPanel>  
             <!-- here is the event xID_Loaded -->  
           <TextBox Loaded="xID_Loaded" Text="{Binding ID}"></TextBox> 
           <Popup Height="Auto" Width="100" IsOpen="True" > 
            <ListView Margin="2"> 
            </ListView> 
           </Popup> 
          </StackPanel> 
         </DataTemplate> 
        </GridViewColumn.CellTemplate> 
       </GridViewColumn> 

       <!-- Second Column --> 
       <GridViewColumn Width="185" Header="Description"> 
        <GridViewColumn.CellTemplate> 
         <DataTemplate> 
          <TextBox Text="{Binding Description}" ></TextBox> 
         </DataTemplate> 
        </GridViewColumn.CellTemplate> 
       </GridViewColumn> 
       etc... 

어쨌든리스트 뷰가 있습니다. Loaded = "xID_Loaded" 이벤트를 열에 사용하여 listview에 새 행을 추가 할 때마다 팝업 컨트롤을 초기화합니다.

따라서 내 코드에서 내가 가진 뒤에 :

private void xID_Loaded(object sender, RoutedEventArgs e) 
{ 
    // sender is the textbox 

    // I can get the popup relative to the sender 
    var stackPanel = (StackPanel)(((Control)sender).Parent); 
    var popup = return (Popup)sp.Children[1]; 

    // every time window moves I want to reset the location 
    // of the popu by doing: 
    this.LocationChanged += (a, b) => 
    { 
     popup.IsOpen = false; // this will ensure that the popup moves with the control 
     popup.IsOpen = true; 
    }; 

    // some more code to initialice the popup 
    // ... 

는 지금은 그 방법이 모든 팝업을 다시 설정합니다 ResetAllPopups()라는 방법을 갖고 싶어. 누군가 스크롤하거나 어떤 이유로 든 모든 popus를 재설정하려고합니다. 다음 발견되는 각각의 팝업을 다시 VisualTreeHelper와 팝업 컨트롤을 찾는 목록보기에서 listviewitems을 반복

:

은 내가이 문제를 해결할 수있을 것이다라는 것을 알고있다.

this.LocationChanged 이벤트 처리기에 가입 된 모든 이벤트를 찾을 수 있다면 좋을 것 같습니다. this.LocationChanged 이벤트에 서브 스크립 션되는 모든 이벤트를 어디서 실행할 수 있습니까?

답변

1

너무 UI 중심적이라고 생각하면 IsOpen을 항목에 바인딩 한 다음 다시 반복하여 Popup 인스턴스를 가져올 필요가 없습니다.

+0

팝업을 사용하지 않으면 팝업 내의 목록보기가 표시되지 않습니다. 이 목록을 사용하여 기본 목록보기 내에 자동 완성 기능을 추가합니다. 또는 스택 패널에 설정할 수있는 속성이있어서 그 바깥 쪽의 내용을 표시 할 수 있습니다. –

+0

@TonoNam : 나는 당신이'Popups'에 대한 참조를 얻을 필요가 없다는 것을 의미했습니다. 물론'Popups' 자체도 마찬가지입니다. 그냥 'IsOpen'을 바인딩하고 바운드 속성을 변경해야합니다. –

0
public event EventHandler reset_Popus; 

    private void xID_Loaded(object sender, RoutedEventArgs e) 
    { 
     // I can get the popup relative to the sender 
     var stackPanel = (StackPanel)(((Control)sender).Parent); 
     var popup = return (Popup)sp.Children[1]; 


     Action<object,EventArgs> tempEvent = (object a, EventArgs b) => 
     { 
      popup.IsOpen = false; 
      popup.IsOpen = true; 
     }; 

     reset_Popus += new EventHandler(tempEvent); 
     this.LocationChanged += new EventHandler(tempEvent); 
    } 


    // finally the method that I needed 
    public void ResetAllPopups() 
    { 
     foreach (var d in reset_Popus.GetInvocationList()) 
     { 
      d.DynamicInvoke(null, null); 
     } 
    }