<
MultiDataTrigger
>
MultiDataTrigger.Conditions
Condition
Binding
=
"{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=CanUserAddRows}"
Value
"False"
/>
"{Binding RelativeSource={RelativeSource Self}, Path=IsSelected}"
"True"
</
Setter
Property
"Background"
"Gold"
public
class
Bridge : FrameworkElement, INotifyPropertyChanged
{
Bridge()
DataContext =
this
;
}
bool
_BoolUserAddRows;
BoolUserAddRows
get
return
set
if
(_BoolUserAddRows != value)
_BoolUserAddRows = value;
RaisePropertyChanged(
"BoolUserAddRows"
);
void
string
prop)
(PropertyChanged !=
null
)
PropertyChanged(
,
new
PropertyChangedEventArgs(prop));
event
PropertyChangedEventHandler PropertyChanged;
Window.Resources
local:Bridge
x:Key
"MyBridge"
DataGrid
x:Name
"dataGrid2"
ItemsSource
"{Binding AllItems2}"
CanUserAddRows
"{Binding BoolUserAddRows, Source={StaticResource MyBridge}}"
HorizontalAlignment
"Left"
VerticalAlignment
"Top"
DataGrid.CellStyle
Style
TargetType
"{x:Type DataGridCell}"
Style.Triggers
This article has also been published on MSDN Samples Gallery as a project you can download and try. It includes two DataGrids, first the broken one, which you can see the error in Visual Studio's Output tab. The second shows the fixed DataGrid, which does not trigger an error when you click to remove a row.