我有一个静态集合:
<CollectionViewSource Source="{Binding Source={x:Static Application.Current}, Path=MarketDataListeners}" x:Key="ficServerMarketDataView"></CollectionViewSource>
是类型为MarketDataListener
的集合。我有一个绑定到这个集合的ListView和一个绑定到这个ListView的选定项目的ContentControl。在ContentControl中,我有一个启动子窗口的按钮(在代码后面)。
我所做的就是像这样跟踪主窗口中选中的项目:
private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
_selectedItem = ((sender as ListView).SelectedValue as MarketDataContainer);
}
然后当控件控件中的按钮被点击时,我执行:
private void ShowComponentsButton_Click(object sender, RoutedEventArgs e)
{
var detailsWindow = new ComponentWindow(_selectedItem);
var button = sender as Button;
if (button == null) return;
detailsWindow.Show();
}
这是ContentControl的绑定:
<ContentControl Name="Detail" Content="{Binding Source={StaticResource ficServerMarketDataView}}"
ContentTemplate="{StaticResource detailsFicTemplate}" VerticalAlignment="Stretch" Foreground="Black" DockPanel.Dock="Bottom" />
是否有可能删除跟踪选定项目的代码,只是启动没有参数的子窗口?子窗口的标题应该是当前选择的MarketDataListener
上的一个属性'Name'。理想情况下,当所选项发生变化时,子窗口不会更新。
Is it possible to remove the code tracking the selected item just launch the child window without a parameter?
我强烈建议您在同一窗口中显示详细信息,
从用户体验的角度来看,这是可取的。您可以使用页面或contentControl来显示detailsWindow数据。在这种情况下,它会很容易实现你正在寻找,所有你需要做的是绑定ContentControl。dataContext到listviewSelected项
否则,如果你只是通过设计创建一个新的窗口,你可以创建一个单独的ViewModel,它将绑定到ListViewSelected项目,每次你将打开DetailsWindow,你将访问这些数据