所有事件我有一個列表視圖火被預訂了特定的事件處理程序
<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」事件來每次向列表視圖添加新行時初始化彈出控件。
因此在我後面的代碼我有:
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。
我知道我將能夠解決此問題:
通過在ListView的listviewitems迭代尋找具有VisualTreeHelper彈出控制然後重新找到的每一個彈出窗口。
我認爲如果我能找到訂閱this.LocationChanged事件處理程序的所有事件會更好。我怎樣才能執行所有被this.LocationChanged事件驅使的事件,就像我在哪裏改變窗口的位置一樣?
如果我不使用彈出窗口內的列表視圖不會顯示出來。我使用該列表在主列表視圖中添加自動完成功能。或者,也許有一個屬性,我可以設置到堆疊面板,以便它的內容將顯示 – 2012-03-20 17:41:51
@TonoNam:我的意思是,你不需要獲得對'Popups'的引用,當然是'Popups'本身應該保持,只需綁定'IsOpen'並更改綁定屬性。 – 2012-03-20 18:24:40