Home > Net >  Conversion of Silverlight 5 RIA to Wpf Issues
Conversion of Silverlight 5 RIA to Wpf Issues

Time:06-03

We're in the process of converting a SL5 RIA service to a WPF front and WCF service as a temporary solution. So far we've been succesfully adjusting all SL components and libraries to WPF counterparts. But we've come at a point where Visual Studio is throwing a series of build errors that we don't understand the origin of.

The old SL solution is maintained with VS 2015 14.0.25431.01. It uses SL5 and .NET 4.0. It builds correctly also after a full clean of the solution. The new WPF solution is made with VS 2019 16.11.15 and uses .NET 4.8.

The 3 errors we are getting on some of our usercontrols are

XDG0036 The "Key" attribute can only be used on an element that is contained in "IDictionary". This error points to line 1 of the xaml code which is the usercontrol itself.

<UserControl
    x:Class="Inspectieprogramma.UserControls.DetailsInspfreq"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    xmlns:converters="clr-namespace:Inspectieprogramma.Converters"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:cmdExtras="http://www.galasoft.ch/mvvmlight"
    xmlns:helpers="clr-namespace:Inspectieprogramma.Helpers"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
>

XDG0040 The property "Resources" can only be set once. This error points to the start of our resource tag, <UserControl.Resources> but there is only a single resource declaration.

<UserControl ...>

    <UserControl.DataContext>
        <Binding Path="Inspectieprogramma" Source="{StaticResource Locator}" />
    </UserControl.DataContext>
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Inspectieprogramma;component/Styles/RadDatetimePickerStyle.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
...
<DataTemplate/>, <ControleTemplate/> and <Style/> definitions
...
    </UserControl.Resources>
<Border>
// All contents
</Border>
</UserControl>

XDG0047 The specified value cannot be assigned. The following type was expected: "ResourceDictionary". This error again points to line 1 of the code as XDG0036 does.

Kr, Emmanuel

CodePudding user response:

you need to place DataTemplate, ControleTemplate and Style definitions inside ResourceDictionary you declare, not just inside UserControl.Resources tag:

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Inspectieprogramma;component/Styles/RadDatetimePickerStyle.xaml" />
        </ResourceDictionary.MergedDictionaries>

        ...
        DataTemplate, ControleTemplate and Style definitions
        ...
    </ResourceDictionary>
</UserControl.Resources>
  • Related