我有DataGrid
个DataGridTemplateColumn
个。
DataGrid
的定义如下:
<DataGrid Grid.Row="1" Grid.Column="2" AutoGenerateColumns="False"
ItemsSource="{Binding SelectedFolder.Documents, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
SelectedItem="{Binding SelectedDocument, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Filename" Width="*" SortMemberPath="Titel">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding Titel}" VerticalAlignment="Center"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Format" Width="Auto" SortMemberPath="Extension">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding Extension}" VerticalAlignment="Center"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Created" Width="Auto" SortMemberPath="DateCreated">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding DateCreated, Converter={StaticResource DateConverter}}" VerticalAlignment="Center"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="User" Width="Auto" SortMemberPath="CreationUser">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding CreationUser, Converter={StaticResource UserIdToUserNameConverter}}" VerticalAlignment="Center"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Delete" Width="Auto" Visibility="{Binding DataContext.User.Permission, Converter={StaticResource UserPermissionToDeleteVisibility}, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Style="{StaticResource buttonStyle}" Command="{Binding DataContext.DialogActionCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}"
CommandParameter="{x:Static helper:ButtonActionTarget.DeleteDocument}" Width="24" Height="24" VerticalAlignment="Center">
<Image Source="{x:Static helper:ImageHelper.Delete}"/>
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
数据已正确更新。遗憾的是,最后一列的Visibility
未正确应用。我在这做错了什么?我的转换器不会随时调用。
转换器看起来像:
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is UserPermission)
{
if ((((UserPermission)value) & UserPermission.Delete) == UserPermission.Delete)
return Visibility.Visible;
}
return Visibility.Collapsed;
}
如果我在Visibility
的{{1}}设置了Button
- 属性,那就可以了。但我希望隐藏完整的专栏。