< Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib" x:Class="WpfApplication1.MainWindow" xmlns:Converters="clr-namespace:WpfApplication1" Title="MainWindow" Height="350" Width="525"> < Window.Resources> < Converters:SelectedEnabledConverter x:Key="SelectedEnabledConverter" /> < /Window.Resources> < Grid> < DataGrid x:Name="grdManifest" Margin="0,0,0,43" > < /DataGrid> < Button Content="Delete" HorizontalAlignment="Left" Margin="119,288,0,0" VerticalAlignment="Top" Width="75" Height="22"> < Button.Style> < Style TargetType="Button"> < Style.Triggers> < DataTrigger Binding="{Binding ElementName=grdManifest, Path=SelectedItems.Count, Converter={StaticResource SelectedEnabledConverter}}" Value="false"> < Setter Property="IsEnabled" Value="False" /> < /DataTrigger> < /Style.Triggers> < /Style> < /Button.Style> < /Button> < /Grid> < /Window>And converter:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Data; namespace WpfApplication1 { public class SelectedEnabledConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return (value as int?).GetValueOrDefault() == 1; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } }