【发布时间】:2014-08-22 01:51:09
【问题描述】:
好的,我这里有一个稍微复杂的功能。我想知道 A)如果我做得正确。如果不是,我应该改变什么? 2) 如果合适,我的问题的最佳解决方案是什么?
我有一个包含项目 ListView 的主窗口。如果我单击其中一个,则此窗口中的右侧网格列应填充 DataGrid,其中包含有关所选项目的信息。如果我单击 ListView 中的另一个项目,它应该会更改为另一个 DataGrid。
我已经看到了一些 ContentPresenter 示例,但我无法让它工作,所以我将其剥离出来,并向您展示我目前拥有的代码。现在,我只有一个项目设置,所以我将继续使用这个驱动程序示例。
DriverGrid.xaml
<UserControl DataContext="{Binding AdminDriver, Source={StaticResource Locator}}">
<Grid>
<DataGrid>
//stuff here for datagrid
</DataGrid>
<Button Content="Edit" Command="{Binding ShowEditWindow}" />
<Button Content="Add" Command="{Binding ShowAddWindow}"/>
</Grid>
</UserControl>
AdminDriver.cs (VM)
//Contains variables, and is the datacontext for the above usercontrol
AdminMain.xaml(查看所有管理内容)
//Contains a bunch of junk for the min admin screen which has the listview with the options in it. If you require this piece of code, I can trim it down but I don't se currently see it's relevance. The DataGrid belongs in this window, I'm assuming in a Content Presenter. Here is the ListView that is in column 1 of 2.
<ListView ItemsSource="{Binding AdminMenu}"
Name="AdminFields"
SelectionMode="Single">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<cmd:EventToCommand CommandParameter="{Binding SelectedItem, ElementName=AdminFields}" Command="{Binding registerSelected}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ListView.ItemTemplate>
<ItemContainerTemplate>
<TextBlock Text="{Binding FieldName}"/>
</ItemContainerTemplate>
</ListView.ItemTemplate>
</ListView>
【问题讨论】:
标签: wpf xaml wpf-controls mvvm-light contentpresenter