Cannot reference Toolkit - c#

I am trying to use the contextmenu with menu items in the toolkit of silverlight. I am working with Silverlight 4.0 and the toolkit is 5.0 (maybe that is the problem to begin with) and it does not let me add a simple Context menu.
I add my reference to the code in the reference folder and select the DLL System.Windows.Controls.Toolkit and System.Windows.Controls.Input.Toolkit. I then add a reference in the XAML file like this:
xmlns:controlsInputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
and I have also tried like this:
xmlns:tk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
I add a simple code like this:
<navigation:Page x:Class="SilverlightApplication6.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:tk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth="640" d:DesignHeight="480"
Title="Page1 Page">
<Grid>
<tk:ContextMenuService.ContextMenu>
<tk:ContextMenu>
<tk:Separator/>
</tk:ContextMenu>
</tk:ContextMenuService.ContextMenu>
</Grid>
</navigation:Page>
and I get this error:
The tag 'ContextMenu' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit'
So, I am either not adding the right reference or there is something messed up in the files or the version of the files.

I work in Silverlight 4 as well, and I'm using the Toolkit from April 2010. It's specific for SL4, you can find it here: http://silverlight.codeplex.com/releases/view/43528
You can choose to download either the .zip or a msi. I picked the .msi, so your Toolkit will be installed in C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Toolkit\{release month year}\Bin, so VS will pick this up automatically. This allows you to add the reference through the interface in VS.
Add the xaml namespace like this:
xmlns:SLToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
And finally, you can use the contextmenu:
<SLToolkit:ContextMenu>
</SLToolkit:ContextMenu>

Related

Load xaml ResourceDictionary from dll

I have made several ResourceDictionaries for our applications team to use with their future applications. I have deployed the contents of the class library project containing these dictionaries to a .dll file and would like to be able to use the dictionaries by adding a reference to the .dll file in a new WPF solution where I hope to make a new application.
The Class Library in my example is called "NWF_Class_Library.dll" and is saved in the same folder in windows explorer as the MainWindow.xaml file. Is it possible to retrieve the resource dictionaries from within it?
I have read articles about the best way for an organisation to arrange their xaml resources, so it seems it must be possible, but all I find is ways to use the "//pack:application:..." syntax to reference xaml within the same solution as the wpf application. Here is a snippet of code, with the Source blank because nothing I have written has worked!
We had hoped that we could add the standard configurations as well as our more normal useful methods etc to a file that can be deployed with applications.
<Window x:Class="dll_ref_included.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<ResourceDictionary Source=""/>
</Window.Resources>
<Grid>
<Button Style="{StaticResource myButton}">This</Button>
</Grid>
</Window>
Try this:
<ResourceDictionary Source="pack://application:,,,/NWF_Class_Library;component/Dictionary1.xaml"/>
...where "NWF_Class_Library" is the name of the referenced assembly and "Dictionary1.xaml" is the name of the ResourceDictionary that is defined in this project.
You can refer to the documentation for more information about pack URIs and how to use them.

The name "ImageViewModel" does not exist in the namespace "clr-namespace:AdminControlCenter.ViewModel"

As the titel say i have the problem that Xaml don´t now my clr namespace, I read the other posts and tried their solution without any success, I rebuild, Start as Admin tried the build conviguration etc.
My Project looks so:
My XAML:
<Controls:MetroWindow x:Class="AdminControlCenter.View.MainView"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:resx="clr-namespace:AdminControlCenter.Properties;assembly=AdminControlCenter"
xmlns:local="clr-namespace:AdminControlCenter;assembly=AdminControlCenter"
xmlns:vm="clr-namespace:AdminControlCenter.ViewModel;assembly=AdminControlCenter"
Title="MainWindow" Height="400" Width="600">
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="White">
<Grid.DataContext>
<vm:ImageViewModel x:Name="imageViewModel"/>
</Grid.DataContext>
And the Error:
And the ImageViedModel:
namespace AdminControlCenter.ViewModel
{
public class ImageViewModel : ViewModel
{
public ImageViewModel()
{
}
.....
The classes are public and show up at the autoformat, when I type for example
"vm:" It also go to the Definition of the Class by using F12.
When I use some MVVM tutorial tests, they are working. But when I try in my Project all ViewModels are not found.
Why doesen´t found the XAMl my ViewModels ?
Edit:
I tried every variation of the assemblies with and without, I also try to delete the suo and try every build configuration, and I restart VS as Admin etc. I also make a new Project with another name and rewrite all classes (Not Copied them) also without any success
I get this error too sometimes, but I can build/deploy anyway.. I think it's a Visual Studio bug.. Are you able to deploy your solution?
Maybe you can try to copy Model and ViewModel's content somewhere else , delete from the project these two files and recreate the files again.. Or.. Do you know how to use the ViewModelLocator class? Since I started use it I never seen that issue again
See here for details about ViewModelLocator: link

XAML Converter in different namespace

I'm developing a c# Windows Phone 8.1 App in VC2013 and stumbled over an odd issue.
To make my Code more 'clean', I decided to put different parts of my App into different folders. There is no problem with calling XAML pages from these folders in the c# code.
BUT I seem to have issues linking these folders in XAML Code itself. For example I have following structure:
root, Files: App.cs+xaml, Mainpage.cs+xaml
|
-- Folder: Login
|
-- Files: LoginPage.cs+xaml
-- Folder: Converters
|
-- Files: converterClass.cs
To use the IValueConverter from the converterClass.cs like I always did, I put the following in the Header of my XAML file:
<Page
x:Class="myApp.Login.LoginPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:meinStundenplaner.Login"
xmlns:myConverter="using:myApp.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Styles/standardStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
<myConverter:DateTimeConverter x:Key="DateTimeConverter" />
... some more converters
</ResourceDictionary>
</Page.Resources>
...
Now it happens, that if I type <myConverter: the autocomplete does find my converter classes like usually, but when compiling (it is compiling) and testing on device none of the converters works and also I get an error in the Error-list saying
The name 'DateTimeConverter' in namespace 'using:myApp.Converters' does not exist.
Where did I go wrong?
wow ... after using VS2015 and the same error persisted, I played a little bit around with settings and stuff.
I kept being curious, why it would compile and deploy even it triggered so many errors. The problem appeared to be inconsistent.
The solution was different than expected:
You have to set Solution Platforms to x86 instead of ARM (which I needed to deploy on device). Luckily VS2015 has this option in a handy shortcut, what you can't say about VS2013.
Nevertheless it's solved...

Can't use WrapPanel in SilverLight Application

I'm building my first Silverlight application and I'm attempting to use a WrapPanel in one of my views. However I am getting the following error.
Error 1 The name "WrapPanel" does not exist in the namespace
"http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit".
My code:
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
...
<toolkit:WrapPanel Height="657" Width="657" />
Do I need to install a package or something? If so, how?
Kindly refer to this link ::
WrapPanel
Actually the WrapPanel control is not a part of Silverlight rather it is a part of Silverlight Toolkit. Before you can use a WrapPanel control, you must download the Silverlight Toolkit. After that you need to add a reference to an assembly. You will get Microsoft.Windows.Controls.dll assembly from the folder where you installed the Silverlight Toolkit. Now, you have to import the Microsoft.Windows.Controls namespace to the page. Once you type xmlns= in your page, you will see Microsoft.Windows.Controls listing in Intellisense.
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
x:Class="Demo.App"
xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls">
<Application.Resources>
<!-- Resources scoped at the Application level should be defined here. -->
<ItemsPanelTemplate x:Key="ExamplePanal">
<controls:WrapPanel/>
</ItemsPanelTemplate>
</Application.Resources>
The above example "xmlns:controls="clr-namespace:Microsoft.Windows.Controls" after adding this dll then the WrapPanel added to the Intellisense. while typing controls: intellisense show WrapPanal in the list.
See the below code here I am adding ExamplePanal.
<Control
ItemsPanel="{StaticResource ExamplePanal}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" />
I think this may help you..
Thank You
Jom George

http://schemas.microsoft.com/winfx/2006/xaml/presentation definition

When you create a new WpfApplication project in Visual Studio you get the following XAML. Copying and pasting the URL http://schemas.microsoft.com/winfx/2006/xaml/presentation into the browser I expected to see the XSD file definition but I get an error. Why?
Thanks.
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
</Grid>
</Window>
The problem is most of wpf developer knows how it works but when you going to explain, it's become much difficult .. below is my try ... due to simplification it become large but i hope if you read to the end, you will understand how the definition thing works ..
Scenario:
I am a wpf beginner developer and searching for a wpf spinner on goggle. i got a link of font.awesome.wpf .. so i started to trying it. below code is written in document to add the spinner ..
<Window x:Class="DemoFontAwesome.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:fa="http://schemas.fontawesome.io/icons/"
Title="MainWindow" Height="350" Width="525">
<Grid Margin="20">
<fa:ImageAwesome Icon="AlignCenter" Spin="False" Height="48" Width="48" />
</Grid>
</Window>
Wow great .... It's working fine !!! ...
Suddenly!! i discover that i added a line there
xmlns:fa="http://schemas.fontawesome.io/icons/"
Not something like
xmlns:fa="clr-namespace:FontAwesome.WPF;assembly=FontAwesome.WPF"
then how visual studio knew which dll contain the ImageAwesome class!!! ... I added only FontAwesome.WPF.dll through nuget ..nothing else i did.. no additional xsd or xml file is there.. The schema link(http://schemas.fontawesome.io/icons/) is not available ...then how??
...Strange!!
However after 1 hours i ended up with below code..
<Window x:Class="DemoFontAwesome.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:fa="http://schemas.fontawesome.io/icons/"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ResourceDictionary>
<fa:CssClassNameConverter Mode="FromIconToString" x:Key="sdfsdf"></fa:CssClassNameConverter>
</ResourceDictionary>
</Window.Resources>
<Grid Margin="20">
<fa:ImageAwesome Icon="AlignCenter" Spin="False" Height="48" Width="48" />
</Grid>
</Window>
The noticable part is fa:ImageAwesome and fa:CssClassNameConverter classes... They are from different namespace (using code behind i already checked it).. and i did not specified one extra line to specify any of FontAwesome.WPF or FontAwesome.WPF.Convertersnamespace.. then how the magic going on!! ..
Solution:
So i downloaded the source code of font.awesome.wpf .. and started search for the text http://schemas.fontawesome.io/icons/ there ... and finally i found the below lines in assembly.cs of font.awesome.wpf project..
[assembly: AssemblyVersion("4.5.0.*")]
[assembly: AssemblyFileVersion("4.5.0.7")]
[assembly: XmlnsPrefix("http://schemas.fontawesome.io/icons/", "fa")]
[assembly: XmlnsDefinition("http://schemas.fontawesome.io/icons/", "FontAwesome.WPF")]
[assembly: XmlnsDefinition("http://schemas.fontawesome.io/icons/", "FontAwesome.WPF.Converters")]
And the whole thing (the magic trick!!) revealed to me ..
In assembly.cs file the component defined the http://schemas.fontawesome.io/icons/ namespace .. so when i add fontawesome.wpf dll ... visual studio got it's namespace definition using refection .. and so how vs knows where the fa tag refers to ... So this is how it resolved to me... :)
Some theory
XML namespace name doesn’t match any particular .NET namespace. There are a
couple of reasons the creators of XAML chose this design. By convention, XML namespaces are often
uniform resource identifiers (URIs) as they are here. These URIs look like they point to a location on the
Web, but they don’t. The URI format is used because it makes it unlikely that different organizations will
inadvertently create different XML-based languages with the same namespace. Because the domain
schemas.microsoft.com is owned by Microsoft, only Microsoft will use it in an XML namespace name.
The other reason that there isn’t a one-to-one mapping between the XML namespaces used in XAML
and .NET namespaces is because it would significantly complicate your XAML documents. The problem
here is that WPF encompasses well over a dozen namespaces (all of which start with System.Windows). If
each .NET namespace had a different XML namespace, you’d need to specify the right namespace for each
and every control you use, which quickly gets messy. Instead, the creators of WPF chose to combine all of
these .NET namespaces into a single XML namespace. This works because within the different .NET
namespaces that are part of WPF, there aren’t any classes that have the same name.
The namespace information allows the XAML parser to find the right class. For example, when it looks
at the Window and Grid elements, it sees that they are placed in the default WPF namespace. It then
searches the corresponding .NET namespaces until it finds System.Windows.Window and System.
Windows.Controls.Grid
A namespace is a URI (a URN or a URL), but a URI is not always a URL. The URI used for namespaces is meant to uniquely identify names to prevent clashed. The XML Namespaces Working Group at the time decided to use a technique already know to uniquely identify things: URIs.
As a result, many people think it should actually point to something real. Occasionally that is true, but more often it is not, and it is not meant to be. It is an identitifier, not a location.
In the case of schemas, it is can be used to denote the target namespace, which is the namespace that must be used in documents that need to validated against the schema. To obtain the schema, you will have to ask the vendor. In this case, the schema can be found at a location similar or equal to C:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas, look for wpfe.xsd (however, to confuse matters more, Microsoft has decided to create an alias for the target namespace, which is why you will not see the same namespace you mentioned).

Categories