Select to view content in your preferred language

Converting Silverlight Library to WPF - Cannot see the controls in WPF App

3061
3
09-04-2010 03:53 PM
RyanCoodey
Frequent Contributor
I am porting a Silverlight Library to a WPF Library (SL4, .NET4)... Got all the issues resolved so that I could compile the WPF library without errors. 

I am now trying to use the WPF library in a WPF application.  I add a control from the library in XAML, it compiles just fine and the app launches, but I never see the controls...  it is like the templates from the dll are not being used or something.  The library has a Generic.xaml that merges all the different control themes together.  The controls show just fine in the corresponding Silverlight library and a Silverlight app.

Things I have tried:

1) In AssemblyInfo.cs, I changed
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
To
[assembly: ThemeInfo(ResourceDictionaryLocation.SourceAssembly, ResourceDictionaryLocation.SourceAssembly)]

I tried this in both the dll and the Apps AssembyInfo.cs

2) All template controls declare their styles like this:
        public Bookmark() 
        { 
#if SILVERLIGHT 
            this.DefaultStyleKey = typeof(Bookmark); 
#endif 
        } 
 
        static Bookmark() 
        { 
#if !SILVERLIGHT 
            DefaultStyleKeyProperty.OverrideMetadata(typeof(Bookmark), new FrameworkPropertyMetadata(typeof(Bookmark))); 
#endif 
        }


Any ideas? What am I forgetting?... I have been doing the Silverlight for awhile now, but this is my first WPF app.  Looking through the ArcGIS Silverlight/WPF toolkit, it is doing what I am trying to, but I can not find anything that I am missing... and the ArcGIS controls show up just fine in the WPF app.

Thanks a lot for any help or ideas!
0 Kudos
3 Replies
MarioVernari
Emerging Contributor
Hard to say without any source.
I've converted the Silverlight Standard Template application to WPF. I've converted the parts of code relying on the Expression SDK, because I don't want to depend from.
In any time I had not problem (except a strange hang when stopping the app in VS2010).
Cheers
Mario
0 Kudos
RyanCoodey
Frequent Contributor
It has something to do with using the controls out of a DLL, like its not using the Generic.xaml in the DLL...

The below test control works fine if it is in the Application and using the apps generic.xaml to merged dictionaries.  But if I move the control, the template, and the merged dictionary to the DLL, it compiles and all, but I do not see the control in the app then.

Test.Theme.xaml
<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:inputToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:local="clr-namespace:SDL.ArcGIS.Client.Toolkit">

    <!-- Dialog Window Style -->
    <Style TargetType="local:Test">
        <!-- Existing Properties -->
        <Setter Property="Width" Value="Auto" />
        <Setter Property="Height" Value="Auto" />
        <Setter Property="HorizontalAlignment" Value="Right" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="Background" Value="#BBAF1E2D" />
        <Setter Property="Foreground" Value="White" />
        <Setter Property="BorderBrush" Value="Black" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="FontSize" Value="12" />
        <Setter Property="FontFamily" Value="Verdana" />
        <Setter Property="FontWeight" Value="Bold" />

        <!-- Template -->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:Test">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
                        <TextBlock Text="Test Control" Foreground="{TemplateBinding BorderBrush}" VerticalAlignment="Center" Margin="0,0,5,0" />
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>


Test.cs
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Data;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Geometry;

namespace SDL.ArcGIS.Client.Toolkit
{
    public class Test : Control
    {
        //Constructors
        public Test()
        {
#if SILVERLIGHT
            this.DefaultStyleKey = typeof(Test);
#endif
        }

        static Test()
        {
#if !SILVERLIGHT
            DefaultStyleKeyProperty.OverrideMetadata(typeof(Test), new FrameworkPropertyMetadata(typeof(Test)));
#endif
        }

        //Methods
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
        }
    }
}


Generic.xaml
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:SDL.ArcGIS.Client.Toolkit">
    
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/SDL.ArcGIS.Client.Toolkit;component/Titlebar/Splitter.Theme.xaml" />
        <ResourceDictionary Source="/SDL.ArcGIS.Client.Toolkit;component/Titlebar/Titlebar.Theme.xaml" />
        <ResourceDictionary Source="/SDL.ArcGIS.Client.Toolkit;component/Toolbar/Toolbar.Theme.xaml" />
        <ResourceDictionary Source="/SDL.ArcGIS.Client.Toolkit;component/Windows/AccordionWindow.Theme.xaml" />
        <ResourceDictionary Source="/SDL.ArcGIS.Client.Toolkit;component/Windows/DialogWindow.Theme.xaml" />
        <ResourceDictionary Source="/SDL.ArcGIS.Client.Toolkit;component/Table Of Contents/TableOfContents.Theme.xaml" />
        <ResourceDictionary Source="/SDL.ArcGIS.Client.Toolkit;component/Grid Splitter/MapDataSplitter.Theme.xaml" />
        <ResourceDictionary Source="/SDL.ArcGIS.Client.Toolkit;component/Grid Splitter/MapDataTabControl.Theme.xaml" />
        <ResourceDictionary Source="/SDL.ArcGIS.Client.Toolkit;component/Bookmark/Bookmark.Theme.xaml" />
        <ResourceDictionary Source="/SDL.ArcGIS.Client.Toolkit;component/Test/Test.Theme.xaml" />
    </ResourceDictionary.MergedDictionaries>

</ResourceDictionary>


Thanks for the help!
0 Kudos
RyanCoodey
Frequent Contributor
Figured it out!!!  I was "linking" to the XAML files in the Silverlight project (for code reuse)... Apparently in both VS2008 and VS2010 there is a bug that if a linked XAML file is in a sub folder, it doesn't compile... Looking at the ESRI Toolkit, I see they pulled all the linked files out to the root!

What I did was put both the Silverlight and WPF projects in the same folder for now (so no linking required), I'll see what issues that brings up, but so far so good.  If this has issues I will just pull the linked files to the root like the ESRI toolkit (I hate things not being organized though).

Hope this helps someone else out... Thanks!
0 Kudos