I stuck couple of hours in trying to get parameter from ContextMenu in Datagrid using MVVM.
The parameter comes from the CommandParameter is always null, out of set {Binding} but it's not what I want.
I new in WPF, so for me it is was not helpful to read answers from here and from others questions. It always remain null.
My code is below:
<DataGrid Grid.Row="2" Margin="25,0,0,4" SelectionMode="Single" AlternationCount="2" Name="dgAltPart" AutoGenerateColumns="False" ItemsSource="{Binding Path=AltPartResult}" HorizontalAlignment="Left" VerticalAlignment="Top"
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Auto">
<DataGrid.ContextMenu>
<ContextMenu >
<MenuItem Header="Delete" CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=PlacementTarget.manufacturer}"
Command="{Binding DeleteManufacturerCommand}"/>
</ContextMenu>
</DataGrid.ContextMenu>
<DataGrid.Columns>
<DataGridTextColumn Header="Manufacturer" Width="175" Binding="{Binding manufacturer}"></DataGridTextColumn>
<DataGridTextColumn Header="Manufacturer Part Number" Width="200" Binding="{Binding manufacturer_pn}"></DataGridTextColumn>
<DataGridTextColumn Header="Price" Width="100" Binding="{Binding price}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
And My ViewModel:
private bool canExecute = true;
public ICommand DeleteManufacturerCommand
{
get
{
if (_deleteManufacturerCommand == null)
{
_deleteManufacturerCommand = new RelayCommand(DeleteManufacturer, param => this.canExecute);
}
return _deleteManufacturerCommand;
}
}
public void DeleteManufacturer(object obj)
{
}
In DeleteManufacturer() I always get the obj with null.
so far tried with all kinds of relative source.
What do I miss?
If you define set ContextMenu property at row level, you could bind directly to the DataContext of each row. Try this:
<DataGrid Grid.Row="2" Margin="25,0,0,4" SelectionMode="Single" AlternationCount="2"
Name="dgAltPart" AutoGenerateColumns="False"
ItemsSource="{Binding Path=AltPartResult}" HorizontalAlignment="Left" VerticalAlignment="Top"
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Auto">
<DataGrid.ItemContainerStyle>
<Style TargetType="DataGridRow">
<Setter Property="Tag" Value="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}}" />
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Header="Delete"
CommandParameter="{Binding}"
Command="{Binding PlacementTarget.Tag.DataContext.DeleteManufacturerCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}"/>
</ContextMenu>
</Setter.Value>
</Setter>
</Style>
</DataGrid.ItemContainerStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Manufacturer" Width="175" Binding="{Binding manufacturer}"></DataGridTextColumn>
<DataGridTextColumn Header="Manufacturer Part Number" Width="200" Binding="{Binding manufacturer_pn}"></DataGridTextColumn>
<DataGridTextColumn Header="Price" Width="100" Binding="{Binding price}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
<DataGrid Grid.Row="2" Margin="25,0,0,4" SelectionMode="Single" AlternationCount="2" Name="dgAltPart" AutoGenerateColumns="False" ItemsSource="{Binding Path=AltPartResult}" HorizontalAlignment="Left" VerticalAlignment="Top" SelectedItem="{Binding SelectedManufacturer}"
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Auto">
<DataGrid.ContextMenu>
<ContextMenu >
<MenuItem Header="Delete" CommandParameter="{Binding SelectedManufacturer}"
Command="{Binding DeleteManufacturerCommand}"/>
</ContextMenu>
</DataGrid.ContextMenu>
<DataGrid.Columns>
<DataGridTextColumn Header="Manufacturer" Width="175" Binding="{Binding manufacturer}"></DataGridTextColumn>
<DataGridTextColumn Header="Manufacturer Part Number" Width="200" Binding="{Binding manufacturer_pn}"></DataGridTextColumn>
<DataGridTextColumn Header="Price" Width="100" Binding="{Binding price}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
and your ViewModel should have a property like this:
private Manufacturer selectedManufacturer;
public Manufacturer SelectedManufacturer
{
get { return selectedManufacturer; }
set { selectedManufacturer = value; OnPropertyChanged(); }
}
Related
I'm trying to create CRUD using WPF C# MVVM. I have Document Type Master with script like below:
my XAML:
<TextBox
Grid.Column="1"
materialDesign:HintAssist.FloatingOffset="0, -18"
IsReadOnly="False"
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
materialDesign:HintAssist.Hint="Document Type"
HorizontalAlignment="Stretch"
FontSize="14"
Margin="0 10 0 20"
Text="{Binding Path=CurrentDocumentType.DocumentTypeName}" />
<DataGrid
x:Name="dgDocumentType"
CanUserAddRows="False"
SelectionUnit="FullRow"
SelectionMode="Extended"
AutoGenerateColumns="False"
IsReadOnly="True"
ItemsSource="{Binding Path=DocumentTypesList, Mode=TwoWay}"
SelectedItem="{Binding Path=SelectedDocumentType, Mode=TwoWay}">
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Foreground" Value="Black" />
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn
Header="ID"
Binding="{Binding Path=IdDocumentType, Mode=TwoWay}"
Visibility="Hidden" />
<DataGridTextColumn
Header="Document Type"
Binding="{Binding Path=DocumentTypeName, Mode=TwoWay}" />
</DataGrid.Columns>
</DataGrid>
And this is my ViewModel:
private DocumentType selectedDocumentType;
public DocumentType SelectedDocumentType
{
get { return selectedDocumentType; }
set
{
selectedDocumentType = value;
CurrentDocumentType = selectedDocumentType;
OnPropertyChanged("SelectedDocumentType");
}
}
private DocumentType currentDocumentType;
public DocumentType CurrentDocumentType
{
get { return currentDocumentType; }
set
{
currentDocumentType = value;
OnPropertyChanged("CurrentDocumentType");
}
}
i'm using CurrentDocumentType = selectedDocumentType; so my textbox always show selected value everytime row in datagrid selected.
The problem is everytime i try to change value in textbox currentDocument Type, selected item in datagrid changes too. i want value in datagrid change when i hit update button, any idea? thanks before.
preview image
Binding for TextBox is TwoWay by default. You need to change it to OneWay if you don't want to change the source.
<TextBox
Grid.Column="1"
materialDesign:HintAssist.FloatingOffset="0, -18"
IsReadOnly="False"
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
materialDesign:HintAssist.Hint="Document Type"
HorizontalAlignment="Stretch"
FontSize="14"
Margin="0 10 0 20"
Text="{Binding Path=CurrentDocumentType.DocumentTypeName, Mode=OneWay}" />
I'm working on an MVVM project and I have this Code in one of the the views:
<GroupBox Header="Defaut" BorderBrush="#FF4EA8DE" FontSize="16" Foreground="#FF436EFF" >
<DataGrid Background="Transparent" FontSize="14" CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True" AutoGenerateColumns="False" Style="{x:Null}"
ItemsSource="{Binding ErrorList}">
<DataGrid.Columns>
<DataGridTextColumn Width="0.5*" Header="{DynamicResource Numéro Cordon}" Binding="{Binding BeadName}"></DataGridTextColumn>
<DataGridTextColumn Width="0.5*" Header="{DynamicResource Indice Image}" Binding="{Binding IndiceImage}"></DataGridTextColumn>
<DataGridTextColumn Width="0.5*" Header="{DynamicResource Défaut}" Binding="{Binding DispDefault}"></DataGridTextColumn>
<DataGridTemplateColumn Header="{DynamicResource Criticité}" Width="0.5*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding IsError, Converter={StaticResource IsErrorToCriticityLevel}, Mode=OneWay}"></Label>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="CmdB:CommandBehavior.Event" Value="MouseDown" />
<Setter Property="CmdB:CommandBehavior.Command" Value="{Binding DataContext.RobotErrorSelectionChangedCommand,
RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type controls:MetroWindow}}}"/>
<Setter Property="CmdB:CommandBehavior.CommandParameter" Value="{Binding Path=SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="BorderBrush" Value="#FF6593CF" />
<Setter Property="Background" Value="#FF6593CF" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding RobotErrorSelectionChangedCommand}" CommandParameter="{Binding Path=SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</DataGrid>
</GroupBox>
What I want to do is to be able to unselect the selected item in this list, however I can't find how to access it.
Here is the code in the ViewModel related to this list:
ObservableCollection<Erreur> _ErrorList;
public ObservableCollection<Erreur> ErrorList
{
get { return _ErrorList; }
set { _ErrorList = value; RaisePropertyChanged("ErrorList");}
}
private RelayCommand<Erreur> _RobotErrorSelectionChangedCommand;
public RelayCommand<Erreur> RobotErrorSelectionChangedCommand
{
get
{
return _RobotErrorSelectionChangedCommand
?? (_RobotErrorSelectionChangedCommand = new RelayCommand<Erreur>(
(Erreur err) =>
{
if (err != null)
{
viewservice.OpenDialog(new ErreurImageViewModel(err), ServiceLocator.Current.GetInstance<MainViewModel>());
}
}));
}
}
Thank you for any help or advice.
You can bind the SelectedItem property in the Datagrid to a property in the VM, and to clear the current selection you can just set the property to: null. That way you can deselect the SelectedItem through the code whenever you want.
You would bind it in your View like this:
<DataGrid ItemsSource="{Binding ErrorList}" SelectedItem="{Binding SelectedError}" ...>
Then in your ViewModel you would add:
private Erreur _selectedError = null;
public Erreur SelectedError
{
get => _selectedError;
set
{
if (_selectedError == value) return;
_selectedError = value;
RaisePropertyChanged(nameof(SelectedError));
}
}
Whenever you want to clear the selection you can just do:
SelectedError = null;
And if you want to select a specific instance from the code you can do:
SelectedError = myInstanceOfError;
Bind the SelectedError property to the SelectedItem Attribute in your XAML.
XAML:
<DataGrid Background="Transparent" FontSize="14" CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True" AutoGenerateColumns="False" Style="{x:Null}" ItemsSource="{Binding ErrorList}" SelectedItem="{Binding SelectedError}">
C# Property:
private Erreur _SelectedError;
public Erreur SelectedError
{
get { return _SelectedError; }
set {
if(_SelectedError != value)
{
_SelectedErrorList = value;
RaisePropertyChanged("SelectedError");
}
}
}
Thank you, both answers are correct with a little modification, I added the :
SelectedItem="{Binding SelectedError}" in the XAML code.
and I had to comment this part to disable the command from working :
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding RobotErrorSelectionChangedCommand}" CommandParameter="{Binding Path=SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
now the SelectedError get the Selected Item.Thanx
I've been reading a lot of answers on SO and I couldn't find a simple one to address my issue. I have a simple datagrid and I've added a checkbox column.
<DataGrid AutoGenerateColumns="False" VirtualizingPanel.IsVirtualizingWhenGrouping="True" EnableColumnVirtualization="True" EnableRowVirtualization="True" VirtualizingPanel.IsVirtualizing="true" ColumnHeaderStyle="{StaticResource lowCase}" x:Name="dtGrid" HorizontalAlignment="Left" CanUserResizeRows="False" ItemsSource="{Binding}" GridLinesVisibility="All" HorizontalContentAlignment="Stretch" CanUserAddRows="false" VerticalAlignment="Top">
<DataGrid.Columns>
<DataGridCheckBoxColumn Header="Audited"></DataGridCheckBoxColumn>
<DataGridTextColumn Binding="{Binding Location}" Header="Location" Visibility="Collapsed"/>
<DataGridTextColumn Binding="{Binding Date, StringFormat=MM-dd-yy}" Header="Date"/>
<DataGridTextColumn Binding="{Binding RegularPaidHours}" Header="Regular Repair Hours"/>
</DataGrid.Columns>
</DataGrid>
My goal is to send an update command everytime a row is checked as audited. Somewhere along the lines of:
MySqlCommand cmd = new MySqlCommand("update MyTable set Location='" + Location + "',Date='" + Date + "',RegularPaidHours='" + RegularPaidHours + "', Audited '"yes" where ID = txt.id' , connection);
So if someone checks a rows, that row gets updated in the db. If not just have it null. Can someone please give me a helping hand with this? I don't really know what's my best option here.
Bind the column to a source property of your class where the Location, Date and RegularPaidHours property are already defined:
<DataGridCheckBoxColumn Header="Audited" Binding="{Binding IsAudited, UpdateSourceTrigger=PropertyChanged}" />
...and do whatever you want in the setter of the property:
private bool _isAuditing;
public bool IsAuditing
{
get { return _isAuditing; }
set
{
_isAuditing = value;
//invoke a command or call a method that updates the DB from here...
Task.Run(() => { UpdateDb(Location, ...) });
}
}
Can send the update command using sql in the code behind? I am looking to do it only with some code-behind.
Then you should replace the DataGridCheckBoxColumn with a DataGridTemplateColumn and handle the Checked and Unchecked event for the CheckBox in the template:
<DataGridTemplateColumn Header="Audited" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Checked="DataGridCheckBoxColumn_Checked" Unchecked="DataGridCheckBoxColumn_Unchecked"
IsChecked="{Binding IsAudited, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<CheckBox Checked="DataGridCheckBoxColumn_Checked" Unchecked="DataGridCheckBoxColumn_Unchecked"
IsChecked="{Binding IsAudited, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
private void DataGridCheckBoxColumn_Checked(object sender, RoutedEventArgs e)
{
CheckBox checkBox = sender as CheckBox;
var model = checkBox.DataContext as YourClass;
//update the DB using the properties of your model...
}
<DataGrid AutoGenerateColumns="False" VirtualizingPanel.IsVirtualizingWhenGrouping="True" EnableColumnVirtualization="True" EnableRowVirtualization="True" VirtualizingPanel.IsVirtualizing="true" ColumnHeaderStyle="{StaticResource lowCase}" x:Name="dtGrid" HorizontalAlignment="Left" CanUserResizeRows="False" ItemsSource="{Binding}" GridLinesVisibility="All" HorizontalContentAlignment="Stretch" CanUserAddRows="false" VerticalAlignment="Top">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Audited">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Command="{Here your command. Most Probably Relative Source Binding}" CommandParameter="{Binding}"></CheckBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding Location}" Header="Location" Visibility="Collapsed"/>
<DataGridTextColumn Binding="{Binding Date, StringFormat=MM-dd-yy}" Header="Date"/>
<DataGridTextColumn Binding="{Binding RegularPaidHours}" Header="Regular Repair Hours"/>
</DataGrid.Columns>
</DataGrid>
And Define corresponding RelayCommand with proper parameter in View Model
xaml
<DataGrid ItemsSource="{Binding Products}" CanUserAddRows="False" AutoGenerateColumns="False" SelectedItem="{Binding SelectedProduct}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="CellEditEnding">
<cmd:EventToCommand Command="{Binding ProdcutCellEditCmd,UpdateSourceTrigger=PropertyChanged}" PassEventArgsToCommand="True"></cmd:EventToCommand>
</i:EventTrigger>
</i:Interaction.Triggers>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding id}" Header="ID" IsReadOnly="True"></DataGridTextColumn>
<DataGridTextColumn Binding="{Binding ParentLCSKU}" Header="LCSKU(Parent)" IsReadOnly="True"></DataGridTextColumn>
<DataGridTextColumn Binding="{Binding ChildLCSKU}" Header="LCSKU(Child)" IsReadOnly="True"></DataGridTextColumn>
<DataGridComboBoxColumn ItemsSource="{Binding Source={StaticResource ProductColors}}" SelectedValueBinding="{Binding Color}" Header="颜色" IsReadOnly="True"></DataGridComboBoxColumn>
<DataGridComboBoxColumn ItemsSource="{Binding Source={StaticResource ProductSizes}}" SelectedValueBinding="{Binding Size}" Header="尺寸" IsReadOnly="True"></DataGridComboBoxColumn>
<DataGridComboBoxColumn ItemsSource="{Binding Source={StaticResource ProductCategories}}" SelectedValueBinding="{Binding Category}" Header="类别" IsReadOnly="True"></DataGridComboBoxColumn>
<DataGridTextColumn Binding="{Binding Cost}" Header="成本"></DataGridTextColumn>
<DataGridCheckBoxColumn Binding="{Binding IsOEM,UpdateSourceTrigger=PropertyChanged}" Header="OEM"></DataGridCheckBoxColumn>
</DataGrid.Columns>
viewmodel
public ProductVM()
{
ProdcutCellEditCmd = new RelayCommand<DataGridCellEditEndingEventArgs>(prodcutDataGridCellEditEnding);
}
public RelayCommand<DataGridCellEditEndingEventArgs> ProdcutCellEditCmd { get; set; }
private void prodcutDataGridCellEditEnding(DataGridCellEditEndingEventArgs e)
{
if (e.EditAction == DataGridEditAction.Commit)
{
var prodcut = e.Row.DataContext as BaseProduct;
SelectedProduct = prodcut;
productSave();
}
}
I want to trigger the CellEditEnding event after the checkbox be checked or unchecked, but this event only fires when the cell lost focus.
Whats wrong with this?
Sorry for my bad English.
It is normal behavior cause event name is CellEditEnding. It means that event is fired after finish of cell edit.
I suggest you to bind to Command property in CheckBox.
If you DataGrid placed in Window, you should write:
<CheckBox Header="OEM" IsChecked="{Binding IsOEM,UpdateSourceTrigger=PropertyChanged}}"
Command="{Binding DataContext.ProdcutCellEditCmd, RelativeSource=
{RelativeSource AncestorType=Window, Mode=FindAncestor}}"}" />
If you DataGrid placed in UserControl, you should write:
<CheckBox Header="OEM" IsChecked="{Binding IsOEM,UpdateSourceTrigger=PropertyChanged}}"
Command="{Binding DataContext.ProdcutCellEditCmd, RelativeSource=
{RelativeSource AncestorType=UserControl, Mode=FindAncestor}}"}" />
You can do one thing in that case you have to update code like
First give the name of your datagrid like
<DataGrid ItemsSource="{Binding Products}" Name="dg" CanUserAddRows="False" AutoGenerateColumns="False" SelectedItem="{Binding SelectedProduct}">
Now you have to bind the Checkbox checked event and pass the row of datagrid so you can access all values of that rows in ViewModel
<DataGridCheckBoxColumn Binding="{Binding IsOEM,UpdateSourceTrigger=PropertyChanged}" Header="OEM">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding CheckBoxChecked,Mode=TwoWay,RelativeSource={RelativeSource AncestorType=DataGrid}}" CommandParameter="{Binding ElementName=dg,Path=SelectedItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</DataGridCheckBoxColumn>
Your RelayCommand should be like
I assume that you have bind the List in your datagrid so based on it your relay command should be
private RelayCommand<BaseProduct> _CheckBoxChecked;
public RelayCommand<BaseProduct> CheckBoxChecked
{
get { return _CheckBoxChecked??(_CheckBoxChecked=new RelayCommand<BaseProduct>(CheckMethod)); }
set { _CheckBoxChecked = value; }
}
void CheckMethod(BaseProduct product)
{
// you can access product here
}
I have a DataGrid and PreviewMouseLeftButtonDown event defined like this:
if (InputDocItemsDataGrid.SelectedItems.Count == 1)
{
foreach (CheckBox checkBox in VisualTreeHelpers.FindVisualChildren<CheckBox>(InputDocItemsDataGrid, "cbxSingleRow"))
{
var row = VisualTreeHelpers.FindAncestor<DataGridRow>(checkBox);
if (row.IsSelected == true)
{
checkBox.IsChecked = true;
}
else
{
checkBox.IsChecked = false;
}
}
}
When I click on some row the SelectedItems.Count is 0, and if I click on the same row again then SelectedItems.Count is 1. I don't understand why is this happening becouse I also have SelectionChanged event for my datagrid defined like this:
private void InputDocItemsDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
(this.DataContext as InputDocsViewModel).SelectedInputItems = new List<int>();
foreach (tblInputDocItem item in InputDocItemsDataGrid.SelectedItems)
{
(this.DataContext as InputDocsViewModel).SelectedInputItems.Add(item.InputDocItemID);
}
if ((this.DataContext as InputDocsViewModel).SelectedInputItems.Count > 1)
{
(this.DataContext as InputDocsViewModel).IsEditEnabled = false;
}
}
And in this event everything works fine, when I click on some row in datagrid i don't have to click twice, my SelectedItems.Count is immediately 1.
Here is my datagrid:
<DataGrid AutoGenerateColumns="False"
IsReadOnly="True"
Name="InputDocItemsDataGrid"
ItemsSource="{Binding Path= InputItems}"
SelectedItem="{Binding Path= InputItem, UpdateSourceTrigger=PropertyChanged}"
SelectionChanged="InputDocItemsDataGrid_SelectionChanged"
PreviewMouseLeftButtonDown="InputDocItemsDataGrid_PreviewMouseLeftButtonDown">
<DataGrid.Columns>
<DataGridTemplateColumn CanUserReorder="False" CanUserResize="False">
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<CheckBox Name="cbxAll" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" Checked="cbxAll_Checked" PreviewMouseLeftButtonDown="cbxAll_PreviewMouseLeftButtonDown" />
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Name="cbxSingleRow" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" PreviewMouseLeftButtonDown="cbxSingleRow_PreviewMouseLeftButtonDown" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="{DynamicResource StockStr}" Binding="{Binding Path= tblInputDoc.tblStock.Name}" />
<DataGridTextColumn Header="{DynamicResource UCodeStr}" Binding="{Binding Path= tblGood.UCode}" />
<DataGridTextColumn Header="{DynamicResource GoodStr}" Binding="{Binding Path= tblGood.Name}" />
<DataGridTextColumn Header="{DynamicResource AmmountStr}" Binding="{Binding Path= Amount, Converter={StaticResource moneyConverter}}" />
<DataGridTextColumn Header="{DynamicResource InputPriceStr}" Binding="{Binding Path= InputPrice, Converter={StaticResource moneyConverter}}" />
<DataGridTextColumn Header="{DynamicResource SuggestedPriceStr}" Binding="{Binding Path= SuggestedPrice, Converter={StaticResource moneyConverter}}" />
<DataGridTextColumn Header="{DynamicResource InputValueStr}" Binding="{Binding Path= InputValue, Mode=OneWay, Converter={StaticResource moneyConverter}}" />
<DataGridTextColumn Header="{DynamicResource VatBaseStr}" Binding="{Binding Path= VatBase, Mode=OneWay, Converter={StaticResource moneyConverter}}" />
<DataGridTextColumn Header="{DynamicResource VatValueStr}" Binding="{Binding Path= VatValue, Mode=OneWay, Converter={StaticResource moneyConverter}}" />
<DataGridTextColumn Header="{DynamicResource InputWithVatStr}" Binding="{Binding Path= InputPriceWithVat, Mode=OneWay, Converter={StaticResource moneyConverter}}" />
</DataGrid.Columns>
</DataGrid>
Does anyone know why is this happening?