I have a listview
<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...
Anyways that listview is binded to an observable collection. I use the Loaded=”xID_Loaded” event on the column to initialize the popup control everytime I add a new row to the listview.
Therefore In my code behind I have:
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
// ...
Now I want to have a method called ResetAllPopups() where that method will reset all popups. in case someone scrolls or for watever reason I want to reset all popus.
I know I will be able to solve this problem by:
iterating through the listviewitems in the listview finding the popup control with VisualTreeHelper then reset each popup that is found.
I think it will be nicer if I could find all the events that are subscribed to this.LocationChanged event handler. How can I execute all the events that are subsribed to the this.LocationChanged event just as if I where to change the location of the window?
You think too UI-centric, just bind the
IsOpento your items, then iterate over them, no need to get aPopupinstance.