I want to add declarations for a Object with type of ObservableCollection in Silverlight Xaml. This is what I have done.
1.Add the xmlns declaration like this:
xmlns:col="clr-namespace:System.Collections.ObjectModel;assembly=System.Windows"
2.Add the ObservableCollection declaration like this:
<col:ObservableCollection x:TypeArguments="sys:String" x:Key="AnaBase">
<sys:String>string1</sys:String>
<sys:String>string2</sys:String>
<sys:String>string3</sys:String>
</col:ObservableCollection>
3.The above code works fine in Vs2010 editor because it doesn't report any errors.
The problem is, when I try to build such xaml it always outputs error such as
"The tag 'ObservableCollection' does not exist in XML namespace 'clr-namespace:System.Collections.ObjectModel;assembly=System.Windows'."
It seems to me that the namespace resolvers in editing and building of VS work in different ways. Could anyone please to explain this phenomenon to me? Thanks a lot.
Finally I found out the answer. The generics is not supported in Silverlight 4. That's why ObservableCollection can't be seen in Intellisense of XAML.
Answer: WPF: Xaml, create an observable collection<object> in xaml in .NET 4.0
Related
I am creating a Resource Dictionary, where I reference all my converters, so there is no need to reference each individual converter.
My converters are in the different assembly, to import them I do the following:
Add reference to external assembly
Create a Resource Dictionary
Add xml namespace referencing Converters assembly
Reference converters
So my Dictionary looks like:
<ResourceDictionary xmlns:Converters="clr-namespace:Client.Utilities.Converters;assembly=Client.Utilities">
<Converters:BoolToBrushConverter x:Key="boolToBrush"/>
</ResourceDictionary>
However I get the following exception when trying to build:
Error 18 The tag 'BoolToBrushConverter' does not exist in XML namespace 'clr-namespace:Client.Utilities.Converters;assembly=.Client.Utilities'. Line 12 Position 6. C:\Resources.Tests\Resources\ResourceDictionaries\Converters\ConvertersResources.xaml 12 6 Client.eZenith.Resources.Tests
Any ideas why that is happening?
Note: From intellisense it seems that namespace for Converters assembly is correct, as all converters show up in the suggestion list after typing <Converter:
Edit: VS and blend designer both are able to find that converter, when rendering control preview.
Edit: I have figured out, that it is nothing to do with dictionaries being merged. The same issue appears, when adding a converter to Window's Resources.
I have found the problem eventually, it is merged resourcedictionary bug introduce in .NET 4.
I have fixed it by adding an empty style into the merged resource dictionary (previously I had a RD where I was merging other RD and nothing else).
here is a blog post which I found recently which describes the same problem.
Try using
<ResourceDictionary xmlns:Converters="clr-namespace:Client.Utilities.Converters;assembly=Client.Utilities">
instead.
Change: clr-namespace instead of namespace.
Whenever I try to reference the following namespace in my XAML, the code compiles and the project starts, but the InitializeComponent method throws an error. Here's the XAML reference:
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
and here's the use of ExtendedVisualStateManager
<ei:ExtendedVisualStateManager/>
The error is this:
The type 'ExtendedVisualStateManager' was not found because 'http://schemas.microsoft.com/expression/2010/interactions' is an unknown namespace. [Line: 19 Position: 37]
Is there a new namespace I need to use to use this control?
Here are some facts.
The Microsoft.Expression.Interactions.dll version 4.0.5.0 contains the namespace Microsoft.Expression.Interactivity.Core.
This Microsoft.Expression.Interactivity.Core contains the type ExtendedVisualStateManager.
The Microsoft.Expression.Interactions.dll version 4.0.5.0 carries a XmlnsDefinition that maps the URL "http://schemas.microsoft.com/expression/2010/interactions" to the namespace Microsoft.Expression.Interactivity.Core.
Hence a project referencing version 4.0.5.0 of Microsoft.Expression.Interactions.dll can contain Xaml using xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" that can then contain ei:ExtendedVisualStateManager.
You'll note I've repeated the version number a few times. If you do have an interactions dll referenced in a Silverlight 4 project but your code doesn't work then perhaps its the wrong version. However in that case Dan's answer should still have worked.
Make sure your Silverlight application has a reference to the Microsoft.Expression.Interactions assembly.
<UserControl
xmlns:ei="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
...other namespaces... />
<VisualStateManager.CustomVisualStateManager>
<ei:ExtendedVisualStateManager/>
</VisualStateManager.CustomVisualStateManager>
</UserControl>
I had everything correct per the other answers and like you, the problem still existed. It was failing at runtime on a usercontrol in my project (and that project did reference Microsoft.Expression.Interactions).
However, that usercontrol was being used on a form in another project. Once I added the reference to Microsoft.Expression.Interactions to the outer project, the runtime error was solved. I was not loading assemblies dynamically and so I'm not 100% certain why this was a problem.
I think you should look in your project's properties. Find the references (Microsoft.Expression.Interactions or/and other "Expression" assemblies you may use, and set the "Copy Local" property to TRUE and try it again.
None of the answers solved this puzzling problem to me.
Apparently I needed Microsoft Expression Blend SDK for Silverlight 4.
Installing it has solved the issue.
I am having a strange issue opening up my UserControl in Expression Blend when using a Silverlight Toolkit control. My UserControl uses the toolkit's ListBoxDragDropTarget as follows:
<controlsToolkit:ListBoxDragDropTarget mswindows:DragDrop.AllowDrop="True" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<ListBox ItemsSource="{Binding MyItemControls}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<controlsToolkit:WrapPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</controlsToolkit:ListBoxDragDropTarget>
Everything works as expected at runtime and looks fine in Visual Studio 2008. However, when I try to open my UserControl in Blend I get XamlParseException: [Line: 0 Position: 0] and I can not see anything in the design view. More specifically Blend complains:
The element "ListBoxDragDropTarget" could not be displayed because of a problem with System.Windows.Controls.ListBoxDragDropTarget: TargetType mismatch.
My silverlight application is referencing System.Windows.Controls.Toolkit from the Nov. 2009 toolkit release, and I've made sure to include these namespace declarations for the ListBoxDragDropTarget:
xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
xmlns:mswindows="clr-namespace:Microsoft.Windows;assembly=System.Windows.Controls.Toolkit"
If I comment out the ListBoxDragDropTarget control wrapper and just leave the ListBox I can see everything fine in the design view without errors. Furthermore, I realized this is happening with a variety of Silverlight Toolkit controls because if I comment out ListBoxDragDropTarget and replace it with
<controlsToolkit:BusyIndicator />
the same exact error occurs in Blend. What is even weirder is that if I start a brand new silverlight application in blend I can add these toolkit elements without any kind of error, so it seems like something dumb that is happening with my project references to the toolkit assemblies.
I'm pretty sure this has something to do with loading the default styles for the toolkit controls from its generic.xaml, since the error has to do with the TargetType and Blend is probably trying to load up the default styles.
Has anyone encountered this issue before or have any ideas as to what may be my problem?
Hi we had exactly the same issue, we solved it by checking the references in the project which was having this problem. All referenced toolkit assemblies should be in the same directory on disk.
Our project reference to the System.Windows.Controls.Toolkit.dll always 'jumped' back to the orginal path which was causing our issue. We solved by editing the project file in notepad++ (or any of your favorite text-editor) and hardcode the path where it could find the assembly.
Hope this helps.
For Visual Studio (maybe Blend too) you need to add a reference to :
System.Windows.Controls.Toolkit.Internals.dll
"C:\Program Files\Microsoft SDKs\Silverlight\v4.0\Toolkit\Apr10\Bin\System.Windows.Controls.Toolkit.Internals.dll"
I'm using Silverlight 5 toolkit and having XamlParseException when using BusyIndicator toolkit control in Expression Blend for SL 5, all above solutions didn't helped but I found another workaround, its rather dirty but allows me to make BusyIndecator work in Expression Blend,
derive from control
public class BusyIndicatorEx : BusyIndicator
{
public BusyIndicatorEx()
{
this.DefaultStyleKey = typeof(BusyIndicatorEx);
}
}
create style for derived control (just copy style from BusyIndicator source code to themes/generic.xaml, and change target type to local:BusyIndicatorEx)
I had the same problem which has been resolved by introducing a dummy reference in code behind to the Wrap Panel.
I know it is a little C++y but I can imagine it is because we have indirect reference to wrap panel inside a template and not on the top level page so the loader don't know what to load on initialization. I really like understand the exact reason, though.
I just referenced System.Windows.Controls.Toolkit and introduce following member in code behind:
System.Windows.Controls.WrapPanel _dummy;
I'm trying to create a HierarchicalDataTemplate (from the Silverlight Toolkit) in code in Silverlight following this advice on creating DataTemplates from code:
Creating a Silverlight DataTemplate in code
However, I haven't been able to get it to work for HierarchicalDataTemplate.
I tried using XamlBuilder that ships with Silverlight Toolkit, but that gives me an error.
I've tried XamlReader, and have included various default and prefixed namespaces, but with no luck.
If I run XamlBuilder's Build method, I get the following string:
<HierarchicalDataTemplate xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" xmlns:attached=\"clr-namespace:MyStuff;assembly=MyStuff\" xmlns=\"clr-namespace:System.Windows;assembly=System.Windows.Controls\"><attached:MyUserControl /></HierarchicalDataTemplate>
The error I get is:
AG_E_PARSER_NAMESPACE_NOT_SUPPORTED
With the Silverlight Xaml parser, the default xmlns must be "http://schemas.microsoft.com/winfx/2006/xaml/presentation", even if you don't use it. So add that xmlns declaration to your Xaml string, and change the System.Windows clr-namespace declaration to use some prefix.
Ok, so I have a general question about WPF. I've messed a little with ASP.NET MVC and in the markup it has intellisense on your viewmodel object so you don't mistype it( i love it).
Enter WPF, I love it, I'm utilizing the MVVM approach and one annoying thing that I have to do is make sure I'm binding correctly to my viewmodel. So I type something up in my xaml, then I either
1) if I'm lazy just run the app and click around
2) If i'm not lazy
a)Look at the current DataContext of the control I'm working with.
b)Go to that ViewModel class look at the properties
c)Find my property and then click back to my view and make sure that I spelled it correctly.
I believe that you can look at your trace output for incorrect bindings at run time, but is there something in the horizon to allow intellisense in xaml. The View needs to know about my ViewModel, so why not expose that in xaml.
I think it would be nice for the IDE to do that for me, meaning, when I type "{Binding " it should go up the visual tree find the first non-null DataContext and display the properties, let me select one and there you have it.
Am I missing something? Are there any alternatives. Any insight?
EDIT:
Regarding the comments below there is a way to set the datacontext at design time e.g.
<Window.Resources>
<DesignTimeData:DesignTimeCustomers x:Key="designTimeCustomersDS" />
</Window.Resources>
which is a snippet from this blog:
http://karlshifflett.wordpress.com/2008/10/11/viewing-design-time-data-in-visual-studio-2008-cider-designer-in-wpf-and-silverlight-projects/
All it does is reference a class within xaml.
So with that in place could not the designer then utilize reflection on the datacontext to give you all of the properties for that class?
VS 2013:
IntelliSense with resolved DataContext
IntelliSense with design time DataContext
So with that in place could not the
designer then utilize reflection on
the datacontext to give you all of the
properties for that class?
Resharper 6 has this feature and can show you members of the d:DataContext in the intellisense, if you set the d:DataContext on the View.
Visual Studio 2010 will support intellisense on Bindings. However, this is limited to the properties of the Binding object itself. For example after typing "{Binding " into the XAML editor I then get intellisense on the remaining properties (Path, ElementName, etc.).
I don't think the type of intellisense regarding the data context you specified would be possible as the data context is set at run-time. I've tried experimenting in VS 2010 by setting the data context directly in the constructor but did not have any luck.
According to :
http://blogs.msdn.com/b/visualstudio/archive/2013/08/09/xaml-editor-improvements-in-visual-studio-2013.aspx
Visual studio 2013 xaml Editor now is supporting IntelliSense for Data Binding
In Visual Studio 2010 there is a binding builder which you can enable
http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/14/how-to-enable-using-the-binding-builder-in-wpf-and-silverlight-applications.aspx
but you still don't get intellisense which is weird.