I used ToggleSwitch control in windowsphone, It works fine in windowsphone7 version, takes Microsoft.Phone.Controls as a assembly reference. But in the windowsphone7.5 it asks assembly reference for ToggleSwitch control, it's not included in Microsoft.Phone.Controls. Anyone know the assembly reference for windowsphone7.5 ToggleSwitch control.
The ToggleSwitch control is part of the Silverlight Toolkit, and is part of the namespace Microsoft.Phone.Controls.
To enable it in your project, add a reference to the toolkit dll (or better yet, use NuGet to install it), and then reference the namespace in your XAML
(I'm sure you already know this stuff, and that the actual alias you choose isn't important as long as you use the same one when adding the control to the XAML - using "toolkit" here because that's what I normally do)
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
and make sure your declaration of the control in the XAML includes the namespace reference...
<toolkit:ToggleSwitch ... ><!-- more stuff here --></toolkit:ToggleSwitch>
Related
I have added the below line of code in App.xaml.cs for enabling xaml compilation in all the pages.
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace MyApp
{
}
Also I have added this line of code in my one of the xaml views to enable ZIndex in a specific control for Android.
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
android:VisualElement.Elevation="10"
So my doubt is, Is it affect the Xaml compilation? If I add the above line of code is it affect my View's Performance?
Note: I am assuming you are using a .NetStd library project and not a Shared Code project as the "container
" of your XAML code and that you are also using the latest version of Xamarin.Forms
android:VisualElement.Elevation="10"
VisualElement.Elevation will become a Forms-based bindable property attached to each control that you are assigning it in when compiled into IL via XAMLC, i.e.
IL_0085: ldsfld [Xamarin.Forms.Core]Xamarin.Forms.BindableProperty [Xamarin.Forms.Core]Xamarin.Forms.PlatformConfiguration.AndroidSpecific.VisualElement::ElevationProperty
So my doubt is, Is it affect the Xaml compilation? If I add the above line of code is it affect my View's Performance?
So it is compiled into IL, the XAML is not embedded in the assembly and of course is present on all platforms that this cross-platform NetStd/PCL assembly is deployed (that is why a platform-based bound property is used). At runtime the property is assigned and yes there is an "overhead" associated to do that:
IL_008a: ldc.r4 10
IL_008f: newobj instance void [netstandard]System.Nullable`1<float32>::.ctor(!0)
IL_0094: box [netstandard]System.Nullable`1<float32>
IL_0099: callvirt instance void [Xamarin.Forms.Core]Xamarin.Forms.BindableObject::SetValue([Xamarin.Forms.Core]Xamarin.Forms.BindableProperty,object)
Note: This "overhead" is on all platforms, it would just be on Android that setting the "native" field's Elevation would actually do anything.
Would it be faster and more memory efficient to directly assign the Elevation in a custom Android renderer, yes, but only you can determine if the (small) gain is worth it to your code base.
Was wondering if someone had a good idea of how to handle this.
In WP7.1, we can utilize the excellent Windows Phone Toolkit to include some useful controls such as LongListSelector and Panorama. These are part of the Microsoft.Phone.Controls.Toolkit assembly.
In WP8, we do not need the toolkit for those two controls because they're part of the official Microsoft.Phone.Controls assembly.
I have multi-targeted my app so that I have two phone projects, WP71 and WP80, where I link files in WP80 to files in WP71.
This works great until I try to use the Panorama or LongListSelector control in a XAML page. In the WP80 project, if I reference the WP80 DLL of the phone toolkit, it does not include the two aforementioned controls because, surprise, they're already present.
The issue is, WP71 needs the namespace declaration at the top of the XAML and the namespace is different for both projects.
WP71:
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
<toolkit:Panorama />
WP80:
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
<phone:Panorama />
I cannot build the projects because each project thinks the namespace is incorrect if I just use one because they need to point to different assemblies.
I don't think I can use compile constants in my XAML, otherwise that would be a fix.
My workaround was originally to just reference the older WP71 DLL in my WP80 project. But other 3rd party libraries bind against the official 8.0 SDK DLL (Caliburn, in my case) so it causes problems.
How can I solve this pickle? The only idea off the top of my head was to resort to code-behind to create the instance of the control :( Is there a better way?
Don't use a link, create a separate view for each.
Another solution might be to create a PanoramaEx control in each of the relative projects and inherit from Panorama. Then the view would reference the PanoramaEx control and you could still use a link to a single view. That's if both UI projects have the same namespace.
Edit: isn't panorama for WP7 in the namespace:
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
I do use my initial solution for ProgressBar and PerformanceProgressBar, I have a ProgressBarEx in each UI project, the WP7 one inherits from ProgressBar and the WP8 one inherits from PerformanceProgressBar and then in the views I reference ProgressBarEx.
Might not be the most elegant solution, but you can try to use a T4 file (.tt file) to generate both targets.
<## template language="C#" hostspecific="true"#>
<## output extension=".xaml"#>
<## assembly name="EnvDTE" #>
<phone:PhoneApplicationPage
x:Class="PhoneAppDemo.Pages.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
<# IServiceProvider serviceProvider = (IServiceProvider)Host;
EnvDTE.DTE dte = (EnvDTE.DTE)serviceProvider.GetService(typeof(EnvDTE.DTE));
var configName = dte.Solution.SolutionBuild.ActiveConfiguration.Name;
if (configName == "WP7") { #>
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
<# }else{ #>
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
<# } #>
>
<# include file="Page.xaml" #>
</phone:PhoneApplicationPage>
In this example, the inner content of the Page is in "Page.xaml". We just encapsulate it in <phone:PhoneApplicationPage> at processor time, based on the target name (usually Debug and Release, but in this example we assumed there was a target WP7).
For other stuff related to a multi-targeted silverlight app, you can always read Maintaining a WP7 and WP8 version of a same Silverlight application.
I've a problem with a datagrid on a simple windows form project (framework 4.0, VS2010).
In the code behind is not possible to access to the datagrid.Columns property. Am I missing an assembly reference?
These are my references:
Microsoft.CSharp,
System,
System.Core,
System.Data,
System.Data.DataSetExtensions,
System.Data.Entity,
System.Deployment,
System.Drawing,
System.Runtime.Serialization,
System.Security,
System.Windows.Forms,
System.Windows.Form.Ribbon35,
System.xml,
System.Xml.Linq,
WindowsBase,
WPFToolkit.Extended
I'm not sure but I don't see the System.Windows.Controls and you need that.
Assembly for datagrid columns: system.windows.controls.datagrid.columns
Also I want to suggest you Resharper a very nice tools when you have missing assemblies.
Maybe I figured out. That property seems to exist for wpf components only. In fact, for Windows form the datagrid assembly is System.Windows.Form while for wpf component is PrsentationFramework (System.Windows.Controls)
Hi I got following error
I added reference from phone.controls.assembly.toolkit but it doesnt work
The tag 'LongListSelector' does not exist in XML namespac 'clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit'.
When you add a new reference to your library, or in this case, your toolkit, you must also add a reference in your XAML code.
For eg:
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
So in your XAML page, go right to the top, you will see a couple lines like the one above.
type xmlns:toolkit="LINK TO YOUR TOOLKIT"
When you type xmlns, intellisense will automatically prompt you to a list of available references. You can scroll down to find it.
Make sure you add a unique name like 'toolkit' or 'tool' after xmlns. So to access the LongListSelector, all you have to do is type
<toolkit:LongListSelector />
I'm trying to embed a XAML file as a resource of my C++/CLI project (Using DevStudio 2005). I found few ways to do it but none of them is working properly.
Method 1. Embed it as a native resource
I used the .rc file to include the .xaml. I can easily load it using the native Win32 calls. Problem: the project is not recompiled if I change the xaml file.
Method 2. Embed it using the linker
I used the linker option "Embed Managed Resourcfe File" and added my xaml file there. I can easily use GetManifestResourceStream() after to load it. Problem: the project is not recompiled if I change the xaml file.
Method 3. Embed it using "Add Existing Item"
I tried to add the xaml file using "Project->Add->Existing Item" and then open my xaml file. Problem: When I popup the xaml file properties, I cannot find any "Build Tool" to compile/embed it. Can I get it from somewhere? Is there a command line I can use as a custom build step?
Method 4. Embed it using a .resx file
I tried several things but I never managed to load it at runtime using GetResourceStream(). For this one I would need a step-by-step procedure.
Can someone please tell me which method I should be using?