0

After a long time doing winform, I'm doing some WPF again and I'm having some issue using a converter.

I've an UserControl, inside of it I've a DevExpress grid:

<UserControl x:Class="X.Y.Z.Views.LogMessagesView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:X.Y.Z.Views"
             xmlns:mvvm="http://prismlibrary.com/"
             xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
             xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
             xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
             xmlns:devExpress="clr-namespace:X.Wpf.Converters.DevExpress;assembly=X.Wpf"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" mvvm:ViewModelLocator.AutoWireViewModel="True">
    <UserControl.Resources>
        <devExpress:CollectionToCriteriaOperatorConverter x:Key="CollectionToCriteriaOperatorConverter"/>
    </UserControl.Resources>
    <dxg:GridControl  SelectionMode="Row" ItemsSource="{Binding EventsList}" FilterCriteria="{Binding VisibleLevels, Converter={StaticResource CollectionToCriteriaOperatorConverter}, ConverterParameter='Level'}">
        <dxg:GridControl.SortInfo>
            <dxg:GridSortInfo FieldName="TimeStamp" SortOrder="Descending" />
        </dxg:GridControl.SortInfo>
        <dxg:GridControl.Columns>
            <dxg:GridColumn FieldName="TimeStamp" Header="Local Computer Time">
                <dxg:GridColumn.EditSettings>
                    <dxe:TextEditSettings DisplayFormat="G"/>
                </dxg:GridColumn.EditSettings>
            </dxg:GridColumn>
            <dxg:GridColumn FieldName="Level" Header="Level" >
                <dxg:GridColumn.DisplayTemplate>
                    <ControlTemplate>
                        <StackPanel Orientation="Horizontal"  DataContext="{Binding EditValue, RelativeSource={RelativeSource TemplatedParent}}">
                            <!-- Convert severity to image -->
                            <TextBlock Text="{Binding Name}" />
                        </StackPanel>
                    </ControlTemplate>
                </dxg:GridColumn.DisplayTemplate>
            </dxg:GridColumn>
            <dxg:GridColumn FieldName="RenderedMessage" Header="Message"/>
        </dxg:GridControl.Columns>
        <dxg:GridControl.View>
            <dxg:TableView ShowFixedTotalSummary="True" AutoWidth="True" Name="view" AllowSorting="False" ShowIndicator="False"  ShowGroupPanel="False" ShowAutoFilterRow="False" AllowColumnFiltering="False" AllowEditing="False" AllowFilterEditor="False" AllowGrouping="False" AllowMasterDetail="False">
                <dxg:TableView.ColumnMenuCustomizations>
                    <dxb:RemoveBarItemAndLinkAction ItemName="BestFitColumns"  />
                </dxg:TableView.ColumnMenuCustomizations>
            </dxg:TableView>
        </dxg:GridControl.View>
    </dxg:GridControl>
</UserControl>

I've declared my Converter in the resources, I use it in my binding. Everything compile, but I got an exception on Runtime:

System.Windows.Markup.XamlParseException occurred
  HResult=-2146233087
  LineNumber=38
  LinePosition=130
  Message='Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number '17' and line position '78'.
  Source=PresentationFramework
  StackTrace:
       at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
       at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
       at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
       at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
       at X.Y.Z.Views.LogMessagesView.InitializeComponent() in E:\Dev\WS1\Branches\ReworkedServer\Solution\AAAAAA\Views\LogMessagesView.xaml:line 1
  InnerException: 
       HResult=-2147467263
       Message=The method or operation is not implemented.
       Source=PresentationFramework
       StackTrace:
            at System.Windows.Baml2006.Baml2006SchemaContext.ResolveBamlType(BamlType bamlType, Int16 typeId)
            at System.Windows.Baml2006.Baml2006SchemaContext.GetXamlType(Int16 typeId)
            at System.Windows.Baml2006.Baml2006Reader.Process_ElementStart()
            at System.Windows.Baml2006.Baml2006Reader.ReadObject(KeyRecord record)
            at System.Windows.ResourceDictionary.CreateObject(KeyRecord key)
            at System.Windows.ResourceDictionary.OnGettingValue(Object key, Object& value, Boolean& canCache)
            at System.Windows.ResourceDictionary.OnGettingValuePrivate(Object key, Object& value, Boolean& canCache)
            at System.Windows.ResourceDictionary.GetValueWithoutLock(Object key, Boolean& canCache)
            at System.Windows.ResourceDictionary.GetValue(Object key, Boolean& canCache)
            at System.Windows.StaticResourceExtension.FindResourceInEnviroment(IServiceProvider serviceProvider, Boolean allowDeferredReference, Boolean mustReturnDeferredResourceReference)
            at System.Windows.StaticResourceExtension.TryProvideValueInternal(IServiceProvider serviceProvider, Boolean allowDeferredReference, Boolean mustReturnDeferredResourceReference)
            at System.Windows.StaticResourceExtension.ProvideValueInternal(IServiceProvider serviceProvider, Boolean allowDeferredReference)
            at System.Windows.StaticResourceExtension.ProvideValue(IServiceProvider serviceProvider)
            at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(MarkupExtension me, IServiceProvider serviceProvider)
       InnerException: 

The Converter if it matters:

public class CollectionToCriteriaOperatorConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        String columnName = parameter as String;
        if (string.IsNullOrEmpty(columnName))
        {
            throw new ArgumentNullException(nameof(columnName), "You have to provide a valid column name");
        }

        IEnumerable collection = value as IEnumerable;
        if (collection == null)
        {
            return null;
        }

        return new InOperator(new OperandProperty(columnName), collection.OfType<object>().Select(x => new OperandValue(x)));
    }
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

I found some other cases, but they were saying that the converter should be initialized before their usage(which seems to be the case, right?)

I'm also using Prism, I don't know if it can brings some other issues(this usercontrol is put into a view).

What did I miss?

J4N
  • 19,480
  • 39
  • 187
  • 340
  • Can you edit in the complete exception? It might give a clue. – Haukinger Mar 07 '16 at 09:55
  • Please see ["Should questions include “tags” in their titles?"](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles), where the consensus is "no, they should not"! –  Mar 07 '16 at 10:03
  • @J4N your converter is fine and should work and filter fine from what i see, , one cause might be that its failing to find the resource, try declaring the converter in the same project just to rule this out rather than importing it from a class library. – Xi Sigma Mar 07 '16 at 10:35
  • @Haukinger This is the complete exception. I just redacted 1 namespace. – J4N Mar 07 '16 at 10:46
  • @AndreasNiedermair Okay, I will take this in account in my future questions – J4N Mar 07 '16 at 10:46

1 Answers1

0

I just found what was the issue. I had a crash of Visual Studio, and Visual Studio reseted the target to "Mixed platform". I don't know why exactly it was not working, but some of our projects doesn't have a target for this platform.

I set it back again to 32bits and now everything is working.

J4N
  • 19,480
  • 39
  • 187
  • 340