Can I use a custom control in a stand-alone XAML file? - silverlight

Quick intro: I have some Silverlight 1 content that people have been editing and putting into HTML pages. Unfortunately, this means a lot of repetative creation of Storyboards, etc. We can use Silverlight 2, but not everyone here is familiar with C#/has Visual Studio. What I would like to do is create some custom controls in C#, output to a DLL, then reference the DLL in the XAML file (just as if it was part of a Silverlight project in VS).
I've tried adding this:
xmlns:mycontrol="clr-namespace:MyControl;assembly=../../content_GLOBAL/controls/MyControl/MyControl"
in the Grid tag that is my root. I know the path to MyControl.dll is correct. When I actually try and use it, though (I add <mycontrol:MyControl></mycontrol:MyControl> to the grid) and I get a parser error. It all seems OK if I don't add the control, even if I leave in the xmlns.
I suppose on some level, this makes sense--looking for an assembly is useful if you are going to build something, and since this XAML isn't in VS, it isn't actually building anything. Is there another way that I can reference, and use a custom control in SL2 in a stand-alone XAML file?

Let me first make sure that I understand you correctly: You have a Silverlight app that doesn't use any managed code and is not packaged in a .xap file. The <object> tag refers to a loose xaml file.
This is the Silverlight 1 app model and can still be used in SL 2, and such apps are referred to as "v1-style apps" (even though they target SL 2 and may use features not present in v1). When an application in this form is used, the Silverlight plugin does not load any of the managed components of the runtime (e.g. the CLR, etc.), so referencing a dll from a v1 style app is not going to work.
However, there might be work-arounds to the challenge you are facing here. One solution might be to use a v2 style app that is packed into a .xap and uses managed assemblies. One of the reasons you gave for not doing this is that other developers one the team are not familiar with C#. This should not be an issue as C# is not a requirement for building apps in SL, you can continue to program against it in JavaScript. And if you are just writing JavaScript code, Visual Studio is not a requirement, since there is nothing to compile. They can just edit the .html/.js files and use the .xap/.dll files that were already compiled. Does this make sense?

Related

Convert wpf application to wpf browser application

Is it possible to convert wpf desktop application to wpf browser application? I want to make my application run from browser.
According to my experience there is no converter available which converts WPF to XBAP.
But I did work with multiple platforms together several time in my project. I do maintain 3 platforms together WPF, Silverlight and XBAP in a single solution having single code base. I keep a common code-base and share files between 3 platforms. To achieve this I suggest you to create a Hello world XBAP application and run it first. You need to have few basic idea about how an XBAP application works. Initially understanding the entry and exit point of the application will be enough for you. Try adding one button in Page and understand how it works. Once it’s done then try to link the existing project files (XAML and CS) one by one into the XBAP project. Understand what you are adding and why are you adding. Yes it's quite a hard work you need to do. But don’t worry XBAP, WPF XAML & C# codes are almost similar. You need to know that Conditional compilation symbols can be set in project properties. So that you will be allowed to write #if XBAP & #endif statement in your code sometimes, because few classes or features may not be supported in XBAP and you need to write specific code for XBAP. As an example Dropshadow related features are not available in XBAP.
Hope this answers your query!

Is it possible to share code between a Silverlight web app and Windows Phone 7 app

I have a simple Silverlight app that I want to run on Windows Phone 7 almost exactly as is. I've created a new Windows Phone 7 project and when I reference the Silverlight app I get a warning that says "Adding a reference to a Silverlight project might not work properly. Do you want to continue?".
If I continue and try to run anyway, the WP7 project never starts or sometimes I get "AG_E_PARSER_BAD_TYPE error" and it points to the line in the xaml I used a control from the Silverlight project .
The code between these two projects is about 99% the same. Is there another way to reuse code then what I am trying? Or how can I get this to work?
I'm not that familiar with the difference between the two platforms, but you can link the code files into a different project without duplicating them. Add existing item, and click on the down arrow next to the 'Add' or OK button. Choose Link.
The typical way of achieving this is by using a pattern like MVVM which will allow you to define a common model and viewmodel layer (perhaps in a separate project) the defining a different view layer that references that common project.
You said it yourself, you will only share MOST of the code, not all of it, so you will, at least at some time, need to create device/front-end specific logic and layout.
Rather than add a Silverlight [presumably class library] project to your WP7 app, try creating a WP7 class library and then link the files from the silverlight library. You will still only have one copy of each file but all your libraries will be built appropraitely for the platform they are running on.
This may also help you identify the cause of the problem. The error AG_E_PARSER_BAD_TYPE suggests that you have a type in the XAML in your Silverlight project which isn't supported on the phone.

Exception when add Silverlight dll in WPF application

When i added the silverlight dll in the wpf application , i got the following exception.
Could not load file or assembly "System.Core, Version=2.0.5.0". The located assembly's manifest definition does not match the
assembly reference.
This is happening only in VS 2010 professional Beta 2.
You cannot use Silverlight directly in a WPF application, as they do not use the same version of the .NET Framework, thus the error message
Could you give some more details on your scenario ?
If you have a WPF app, you have more than what Silverlight can give to you.
If you are building a solution with multiple products, and one is WPF for the desktop, one is Silverlight for the Web, you need to create 2 different projects in VS.
Take a look at the source tree here:
http://expressionblend.codeplex.com/
Specifically, the Expression.Samples.Interactivity.Design branch.
This shows a few examples of how to put in property editors for use with Blend. I'm not sure if the same concept is transportable to the Cider design surface, but heck, Blend is nicer for pure XAML editing anyways. :)

Final steps in using MVVM to decouple GUI from business logic?

Just recently, I learned about using MVVM to decouple GUIs from the underlying model. I ended up learning as much as I could to convert my current application over to MVVM, and was largely successful. Now I need to figure out how to actually take a GUI generated in Blend and use it in place of my current GUI, which was designed in Visual Studio. I can't find any resources on the web for making this as seamless as possible. I'd like to know what you all have done and have had work for you.
My ultimate solution would be something that would allow me to, at runtime, select a skin from a menu and immediately have the GUI change from the current one to another that the user selects. Can anyone point me to posts that explain how to do this?
My current goal is less ambitious -- I'd like to be able to add my new Blend GUI into my Visual Studio project and when I compile, have the new Blend GUI appear. If I want to go back to the old GUI, I would have to recompile. For now, that is okay.
I've got my Blend project added to my VS2008 solution, and have set it to be the startup application. That works fine -- if I run the app, my new GUI appears instead of the old one. The problem now is that it needs DLLs that are actually in a different folder -- the bin\Debug folder of the original startup application. Am I supposed to leave my original GUI as the startup application, and then have its App codebehind load the other GUI?
Also, each of the respective GUIs needs a reference to the ViewModel. In my case, I was just instantiating it in my current GUI class. For the Blend GUI, I instantiated one there as well, since only one of the GUIs will be active. Is this where something like the Unity framework should be used?
Sorry about all of the possibly-incoherent questions, but I'm not quite sure how I should proceed from here. I feel like I'm so close to proving to myself that MVVM is the way to go from a GUI standpoint (I'm already sold on the testability bit).
All the examples I've seen dynamically switch GUI appearance by using some form of ResourceDictionary swapping. A few links:
Load XAML Resource Dictionaries at Runtime
WPF change theme/style at runtime
Hope that helps.
I found a mistake, where in one part of my code I was using the wrong property to get at the currently-running assembly's path. I am now using
System.Reflection.Assembly.GetExecutingAssembly().Location
Although this does work, it only works if I copy the exe from the Blend project's bin\Debug folder into my main application's bin\Debug folder. I will have to live with this by using a post-build event, I guess. I was so spoiled for the past several months working with .NET, where I didn't have to do this (like before in C++) because all of the referenced assemblies get automatically copied over. If I want to debug any code-behind, I also have to set the starting executable in the Blend project's settings, which is inconvenient as well, especially when working on different computers where the paths aren't set up the same. Any suggestions here would also be appreciated!

Linked Themes/Generic.xaml Files will not work in visual studio 2008

i have a project that i am doing and i need to share the code between silverlight and WPF Assembly problem is that even though the wpf assembly is the owner of that file
and the silverlight assembly only has a link to the file, all of the build actions are page everything is correct. if i make the silverlight assembly the owner then silverlight works and wpf doesnt, and currently with wpf being the owner i dont get any errors at all it just never styles the control like it cannot find it..
Note: both projects exists in the same solution.
this scenario builds and runs fine
wpf project
|__Themes
|__Generic.xaml
|__SomeControl.cs
this scenario builds and runs but will not display the control
if i change them from linked to normal it will work fine.
i just want to share this source code and not have multiple versions of the same file floating around.
SilverlightProject
|__Themes
|__"Linked"Generic.xaml
|__"Linked"SomeControl.cs
sorry for my corny Tree view representation
+++++++ UPDATE +++++++++
i have noticed when using any linked file regardless of if it is silverlight or WPF
the link file will not build into the Themes folder in the resource only the root.
i used reflector to see where my resources ended up after compilation of the assembly including the linked file and they ended up in the root , so with that being said. is there a way to prevent this or a fix for this if this is indeed non intended behavior .
i would really love to get this figured out as it has been driving me insane for a while now.
Silverlight XAML and WPF XAML do not have the same namespace - so they aren't directly reusable.
My mistake - you're right - now with Silverlight 3 the namespaces are the same:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml
What is the Build Action in the Property Pane for the XAML?

Resources