Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I just ran into this issue, in a small POC althought I got it to work in a bigger project and I managed to find why. Don't know if it can helps, but here his the context and the solution.</p> <p>The problem appeared when trying to bind a command to a Button in an Xceed datagrid, which itemSource was bind on a collection exposed in my viewModel.</p> <p>THE VIEW : </p> <pre><code>&lt;UserControl x:Class="UnIfied.Module.UI.Client.Screens.Alerts.AlertsView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:DataGrid="clr-namespace:Xceed.Wpf.DataGrid;assembly=Xceed.Wpf.DataGrid" xmlns:xcdg="clr-namespace:Xceed.Wpf.DataGrid.Views;assembly=Xceed.Wpf.DataGrid" xmlns:ThemePack="clr-namespace:Xceed.Wpf.DataGrid.ThemePack;assembly=Xceed.Wpf.DataGrid.ThemePack.1"&gt; &lt;Grid&gt; &lt;DataGrid:DataGridControl Grid.Column="0" Name="alertsBlotter" ItemsSource="{Binding AlertsSource}" SelectionMode="Single" NavigationBehavior="RowOnly" ItemScrollingBehavior="Immediate" ReadOnly="True" AutoCreateColumns="false"&gt; &lt;DataGrid:DataGridControl.Columns&gt; &lt;DataGrid:UnboundColumn FieldName="Acquit" Title="Acquit Alert" ReadOnly="True" ShowInColumnChooser="False"&gt; &lt;DataGrid:UnboundColumn.CellContentTemplate&gt; &lt;DataTemplate&gt; &lt;Button DataContext="{Binding Path=DataContext, RelativeSource={RelativeSource AncestorType={x:Type DataGrid:DataRow}}}" Content="X" Command="{Binding AcquitAlertCommand}"/&gt; &lt;/DataTemplate&gt; &lt;/DataGrid:UnboundColumn.CellContentTemplate&gt; &lt;/DataGrid:UnboundColumn&gt; &lt;DataGrid:Column FieldName="AlertId" ReadOnly="True" Title="Alert Id" IsMainColumn="True" /&gt; &lt;DataGrid:Column FieldName="Time" ReadOnly="True" Title="Creation Time" /&gt; &lt;DataGrid:Column FieldName="AlertStatus" ReadOnly="True" Title="Status" /&gt; &lt;DataGrid:Column FieldName="RelatedTrade" ReadOnly="True" Title="CT Id" /&gt; &lt;DataGrid:Column FieldName="Status" ReadOnly="True" Title="CT Status" /&gt; &lt;/DataGrid:DataGridControl.Columns&gt; &lt;DataGrid:DataGridControl.Resources&gt; &lt;Style x:Key="{x:Type DataGrid:ScrollTip}" TargetType="DataGrid:ScrollTip"&gt; &lt;Setter Property="HorizontalAlignment" Value="Center" /&gt; &lt;Setter Property="VerticalAlignment" Value="Center" /&gt; &lt;/Style&gt; &lt;/DataGrid:DataGridControl.Resources&gt; &lt;DataGrid:DataGridControl.View&gt; &lt;xcdg:TableView&gt; &lt;xcdg:TableView.Theme&gt; &lt;ThemePack:WMP11Theme /&gt; &lt;/xcdg:TableView.Theme&gt; &lt;/xcdg:TableView&gt; &lt;/DataGrid:DataGridControl.View&gt; &lt;/DataGrid:DataGridControl&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>THE VIEWMODEL</p> <pre><code>class AlertsViewModel : Presenter&lt;IAlerts&gt; { private readonly IAlertsService alertsService; public AlertsViewModel(IAlerts view, IAlertsService aService) : base(view) { alertsService = aService; view.SetDataContext(this); } public ObservableCollection&lt;AlertAdapter&gt; AlertsSource { get { return alertsService.AlertsSource; } } } </code></pre> <p>THE ADAPTER (which will then be represented by a row in the datagrid). Relay command is a basic ICommand implementation.</p> <pre><code>public class AlertAdapter : BindableObject { private readonly RelayCommand acquitAlert; public AlertAdapter() { AlertStatus = AlertStatus.Raised; acquitAlert = new RelayCommand(ExecuteAqcuiteAlert); } public RelayCommand AcquitAlertCommand { get { return acquitAlert; } } private void ExecuteAqcuiteAlert(object obj) { AlertStatus = AlertStatus.Cleared; } private static readonly PropertyChangedEventArgs AlertStatusPropertyChanged = new PropertyChangedEventArgs("AlertStatus"); private AlertStatus alertStatus; /// &lt;summary&gt; /// Gets or sets the AlertStatus /// &lt;/summary&gt; public AlertStatus AlertStatus { get { return alertStatus; } set { if (AlertStatus != value) { alertStatus = value; RaisePropertyChanged(AlertStatusPropertyChanged); } } } private static readonly PropertyChangedEventArgs AlertIdPropertyChanged = new PropertyChangedEventArgs("AlertId"); private Guid alertId; /// &lt;summary&gt; /// Gets or sets the AlertId /// &lt;/summary&gt; public Guid AlertId { get { return alertId; } set { if (AlertId != value) { alertId = value; RaisePropertyChanged(AlertIdPropertyChanged); } } } private static readonly PropertyChangedEventArgs StatusPropertyChanged = new PropertyChangedEventArgs("Status"); private ComponentTradeStatus status; /// &lt;summary&gt; /// Gets or sets the CtStatus /// &lt;/summary&gt; public ComponentTradeStatus Status { get { return status; } set { if (Status != value) { status = value; RaisePropertyChanged(StatusPropertyChanged); } } } private static readonly PropertyChangedEventArgs RelatedTradePropertyChanged = new PropertyChangedEventArgs("RelatedTrade"); private Guid relatedTrade; /// &lt;summary&gt; /// Gets or sets the RelatedTrade /// &lt;/summary&gt; public Guid RelatedTrade { get { return relatedTrade; } set { if (RelatedTrade != value) { relatedTrade = value; RaisePropertyChanged(RelatedTradePropertyChanged); } } } private static readonly PropertyChangedEventArgs TimePropertyChanged = new PropertyChangedEventArgs("Time"); private DateTime time; /// &lt;summary&gt; /// Gets or sets the Time /// &lt;/summary&gt; public DateTime Time { get { return time; } set { if (Time != value) { time = value; RaisePropertyChanged(TimePropertyChanged); } } } } </code></pre> <p>And here is the exception generated as soon as my app tried to create an adapter and add it to the collection</p> <p>System.NotSupportedException was unhandled Message="'CommandConverter' is unable to convert 'UnIfied.Module.UI.Client.Adapters.RelayCommand' to 'System.String'." Source="System" StackTrace: at System.ComponentModel.TypeConverter.GetConvertToException(Object value, Type destinationType) at System.Windows.Input.CommandConverter.ConvertTo(ITypeDescriptorContext context, CultureInfo culture, Object value, Type destinationType) at System.ComponentModel.TypeConverter.ConvertTo(Object value, Type destinationType) at System.Windows.Controls.ContentPresenter.DefaultTemplate.DoDefaultExpansion(TextBlock textBlock, Object content, ContentPresenter container) (ETC.)</p> <p><em><strong>The issue was caused by the fact that my datagrid was configured to AutoCreateColumns (i.e. based on the properties of the adapter). Just switched this property to false and then all went straight again.</em></strong></p> <p>Hope this will help you guys !</p> <p>--Bruno</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload