我有以下委托命令:
视图模型
使用 Prism.Mvvm; 使用 System.Collections.ObjectModel;
命名空间 Photography.ViewModels { 公共类 ApertureDataGridViewModel : BaseViewModel {
private readonly ConnectedRepository _repo = new ConnectedRepository();
public DelegateCommand<object> SelectionChangedCommand { get; private set; }
public ObservableCollection<Aperture> Apertures { get; set; }
public ApertureDataGridViewModel()
{
SelectionChangedCommand = new DelegateCommand<object>(SelectionChanged);
Apertures = new ObservableCollection<Aperture>(_repo.GetApertures());
}
public void SelectionChanged(object param)
{
if (param == null)
return;
}
看法
<UserControl x:Class="Photography.Views.ApertureDataGridView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:vw="clr-namespace:Photography.Views"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True">
<Grid>
<Grid.Resources>
<vw:TableEditWindow x:Key="TableEditWindow"/>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<DataGrid x:Name="DataGridEdit"
AreRowDetailsFrozen="True"
AutoGenerateColumns="False"
Grid.Column="0"
Grid.Row="0"
DisplayMemberPath="{Binding ApertureName}"
IsReadOnly="False"
ItemsSource="{Binding Apertures}"
SelectionMode="Single"
SelectionUnit="FullRow"
Style="{DynamicResource SelectorDataGrid}"
VerticalAlignment="Top"
VerticalScrollBarVisibility="Auto">
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="DataGridCell.IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource DatagridRowSelected}" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<prism:InvokeCommandAction Command="{Binding SelectionChangedCommand}"
CommandParameter="{Binding SelectedItem,
ElementName=DataGridEdit}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<DataGrid.Resources>
<Style TargetType="DataGridColumnHeader">
<Setter Property="Background" Value="{StaticResource MainBackgroundColor}"/>
<Setter Property="BorderBrush" Value="{DynamicResource MainForegroundColor}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource MainForegroundColor}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding ApertureId}" Visibility="Hidden"/>
<DataGridTextColumn Binding="{Binding ApertureName}" Header="Name" Width="10*"/>
<DataGridCheckBoxColumn Binding="{Binding Active}" Header="Active" Width="3*"/>
<DataGridTextColumn Binding="{Binding Notes}" Header="Notes" Width="10*"/>
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<DockPanel LastChildFill="False" Margin="5 5 5 5 ">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height=" auto"/>
</Grid.RowDefinitions>
<Label Grid.Column="0" Grid.Row="0" Content="Name: " Style="{DynamicResource LabelExpandedRow}"/>
<TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding ApertureName}" VerticalAlignment="Center"/>
<Label Grid.Column="0" Grid.Row="1" Content="Active: " Style="{DynamicResource LabelExpandedRow}"/>
<TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding Active}" VerticalAlignment="Center"/>
<Label Grid.Column="0" Grid.Row="2" Content="Notes: " Style="{DynamicResource LabelExpandedRow}"/>
<TextBox Grid.Column="1" Grid.Row="2" Text="{Binding Notes}" Style="{StaticResource TextBoxExpandedRow}"/>
</Grid>
</DockPanel>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
</Grid>
</UserControl>
调用窗口视图
<!--row 2-->
<ContentControl
Grid.Column="0"
Grid.ColumnSpan="3"
Grid.Row="2"
Margin="10 10 10 10"
Visibility="{Binding ViewVisible,
Converter={StaticResource ControlViewVisibleConverter},
ConverterParameter=Aperture}">
<vw:ApertureDataGridView Visibility="Visible"/>
</ContentControl>
我在应用程序的不同部分使用了完全相同的代码。谁能确定我做错了什么?