We are currently migrating our app from VB6 to Net. As the Net forms will be in the minority we want them to blend in as good as possible with the VB6 forms. I thought that forcibly applying the Classic theme would accomplish this. This should be easy but I can't find how to do it. The examples provided target the Aero theme or Net3 which seems to have differently named referenced assemblies.
There are two ways to accomplish this:
Reference the classic.xaml file that is embedded in the Framework:
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Classic;component/themes/classic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
`
Download the extracted classic.xaml file from here
This file holds a reference to the PresentationUI.dll which does not seem to be part of Net 4 framework. There is just one quixotic Control using this reference, so when you remove the reference and the control you are set to go!
More info here
Related
In my xamarin forms application, I want to store all colors and fonts information that can be accessed through out the application. One of the most obvious ways is adding them as ResourceDictionary in app.xaml.
App.xaml
<ResourceDictionary>
<Color x:Key="Primary">#78909c</Color>
<Color x:Key="PrimaryDark">#4b636e</Color>
<Style TargetType="NavigationPage">
<Setter Property="BarTextColor" Value="{StaticResource NavigationText}" />
</ResourceDictionary>
I have seen these kind of implementations in sample applications but I was wondering for enterprise level applications are they any efficient or better ways to do it?
If so, can anyone advice a better approach and some example or source with the reason behind it?
MODERATORS
I know this question is more about asking a better approach and has no right and wrong answers but I want to find an efficient way or enterprise level implementation for this. So please don't mark it to close.
It really depends on context and what you need to achieve.
One reason why you may not want to have colors and fonts in your main app.xaml file is readability and maintainability. This is quite subjective however.
A second reason why you may want to split out your colors and fonts is if you need to conditionally apply them or they belong to a Xamarin.Forms theme.
Finally note that if you do require multiple resource dictionaries, you may need to look at the Merged Dictionaries feature, which is available from Xamarin.Forms 2.5 onwards (I previously had to roll my own!). This blog post by the author of the official implementation also has more information.
I am reading a design presentation to try and learn some more about android UI. On slide 17, it explains to inherit styles.
https://docs.google.com/file/d/0Bz3qX4EBhUvwZWlHekI3Y0wxSUk/view?sle=true
The developer then says to "Use the framework" and access styles to style your UI. For example, he uses
<style name="MyTheme" parent="android:Theme.Holo.light" />
for sdk versions 11+ in the styles.xml folder. And in the manifest he then sets the theme to "MyTheme". After, he says to reference styles from the current theme, such as
<TextView
style="?android:ListSeparatorTextViewStyle"
...
... />
However, this gives an error that says missing styles. So I researched this and instead found a different way of implementing this as
#android:style/Widget.Holo.Light.TextView.ListSeparator
which gave me an error saying the resource is not public.
So my question is, how can I organize my style.xml, manifest, and layouts to implement android styles like the ones above? What do I need to check to be able to access these styles? Where can I learn about proper organization of these folders and style inheritance? I have tried reading documentation on the android website, but cannot find much help anywhere else. Any advice on where to find other sources on sample code on proper ways to design UI are welcome as well. Thanks for any help.
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'm creating an Activity Library in Visual Studio 11 Beta (although I've repeated all my steps in VS2010 with the same result), targeting the .NET 4.0 framework.
As I started entering arguments via the Workflow Designer, I noticed the "Enter a VB Expression" message in the Default Value box. I'm not sure how to change the language context from VB to C#.
To create the project, I followed these steps:
Go to File> New and select Project...
In the Installed> Templates section of the New Project dialog window, select Visual C#> Workflow> Activity Library
Name the project, as usual, and click OK
And that's basically it. I noticed then that the default Activity1.xaml file was expecting VB in the default values fields. I deleted it and then followed these steps to create a new Activity:
Right-click on the project and select Add> New Item...
In the Add New Item dialog window, navigate to Installed> Visual C# Items> Workflow> Activity
Name the Activity and click OK
It was the same result, the Default Value fields are expecting a VB expression.
When I look at the XAML code, I can clearly see the Microsoft.VisualBasic.Activities namespace listed and a VisualBasic.Settings element, but I'm not sure what to do to change it; everytime I try, I just end up screwing things up. Here's the XAML code being generated:
<Activity mc:Ignorable="sads sap" x:Class="THINKImport.CustomerAddOrderAdd"
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:local="clr-namespace:THINKImport.THINKWebReference"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities"
xmlns:s="clr-namespace:System;assembly=System.Core"
xmlns:s1="clr-namespace:System;assembly=System"
xmlns:s2="clr-namespace:System;assembly=System.ServiceModel"
xmlns:s3="clr-namespace:System;assembly=mscorlib"
xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
xmlns:t="clr-namespace:THINKImport"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<x:Members>
<x:Property Name="user_login_data" Type="InArgument(local:user_login_data)" />
<!--Removed the other properties for brevity-->
</x:Members>
<sap:VirtualizedContainerService.HintSize>440,440</sap:VirtualizedContainerService.HintSize>
<mva:VisualBasic.Settings>Assembly references and imported namespaces for internal implementation</mva:VisualBasic.Settings>
</Activity>
I was able to figure out the issue.
First, though, I was able to discover the root cause here. In a nutshell, it says VB.NET must be used in the Expression Editor even if the program is in C#.
So, I was kinda bummed about that, but I decided to take another crack at the XAML code because, in working through the WF tutorials, there was most definitely an activity I was working on in the designer that would accept Expressions in C#. I opened up that project and went through the XAML code.
It's then that I noticed this line:
<sap2010:ExpressionActivityEditor.ExpressionActivityEditor>C#</sap2010:ExpressionActivityEditor.ExpressionActivityEditor>
I searched the MSDN library and found the documentation for the ExpressionActivityEditor class. As best as I can tell, this is new to .NET 4.5. In my particular case, there isn't any reason I can't target .NET 4.5 in my project, so I changed it. Once the solution reopened, right away, all the Expression Editor text fields and boxes would accept C#. In order to "start fresh", I deleted the activity file I had been working on and created a new one. If anyone's interested, here's that generated XAML code:
<Activity mc:Ignorable="sap sap2010 sads" x:Class="THINKImport.CustomerAddOrderAdd"
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
xmlns:sap2010="http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation"
xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:THINKWebReference="clr-namespace:THINKImport.THINKWebReference">
<x:Members>
<x:Property Name="user_login_data" Type="InArgument(THINKWebReference:user_login_data)">
<x:Property.Attributes>
<RequiredArgumentAttribute />
</x:Property.Attributes>
</x:Property>
<x:Property Name="customer_data" Type="InArgument(THINKWebReference:customer_data)" />
<!--Remainder of Properties removed for brevity-->
</x:Members>
<sap2010:ExpressionActivityEditor.ExpressionActivityEditor>C#</sap2010:ExpressionActivityEditor.ExpressionActivityEditor>
<TextExpression.NamespacesForImplementation>
<sco:Collection x:TypeArguments="x:String">
<x:String>System</x:String>
<x:String>System.Collections.Generic</x:String>
<x:String>System.Data</x:String>
<x:String>System.Linq</x:String>
<x:String>System.Text</x:String>
</sco:Collection>
</TextExpression.NamespacesForImplementation>
<TextExpression.ReferencesForImplementation>
<sco:Collection x:TypeArguments="AssemblyReference">
<AssemblyReference>mscorlib</AssemblyReference>
<AssemblyReference>System</AssemblyReference>
<AssemblyReference>System.Core</AssemblyReference>
<AssemblyReference>System.Data</AssemblyReference>
<AssemblyReference>System.ServiceModel</AssemblyReference>
<AssemblyReference>System.Xml</AssemblyReference>
</sco:Collection>
</TextExpression.ReferencesForImplementation>
<sap2010:WorkflowViewState.IdRef>
THINKImport.CustomerAddOrderAdd_1
</sap2010:WorkflowViewState.IdRef>
<sap2010:WorkflowViewState.ViewStateManager>
<sap2010:ViewStateManager>
<sap2010:ViewStateData Id="THINKImport.CustomerAddOrderAdd_1" sap:VirtualizedContainerService.HintSize="440,440" />
</sap2010:ViewStateManager>
</sap2010:WorkflowViewState.ViewStateManager>
</Activity>
So, quite a bit different (to me, anyways) but I can use C# now, so I'm happy.
C# Expressions
Previously, all expressions in workflows can only be written in Visual
Basic. In .NET Framework 4.5 RC, Visual Basic expressions are only
used for projects created using Visual Basic. Visual C# projects now
use C# for expressions. A fully functional C# expression editor is
provided which capabilities such as grammar highlighting and
intellisense. C# workflow projects created in previous versions that
use Visual Basic expressions will continue to work.
As of Beta 1, C# expressions are validated at design-time. Errors in
C# expressions will be marked with a red wavy underline.
More: What's New in Windows Workflow Foundation in .NET 4.5
I am using the Consumer Preview of Windows 8 to create a Metro app. Whenever I add a new IValueConverter to a XAML page I receive the following exceptions from within the StandardStyles.xaml file:
The name "DictionaryEntry" does not exist in the namespace "using:System.Collections"
The errors point to this section of the StandardStyles.xaml file:
<ResourceDictionary.ThemeDictionaries>
<Collections:DictionaryEntry x:Key="Default">
<Collections:DictionaryEntry.Value>
<ResourceDictionary>
<x:String x:Key="BackButtonGlyph"></x:String>
<x:String x:Key="BackButtonSnappedGlyph"></x:String>
</ResourceDictionary>
</Collections:DictionaryEntry.Value>
</Collections:DictionaryEntry>
<Collections:DictionaryEntry x:Key="HighContrast">
<Collections:DictionaryEntry.Value>
<ResourceDictionary>
<x:String x:Key="BackButtonGlyph"></x:String>
<x:String x:Key="BackButtonSnappedGlyph"></x:String>
</ResourceDictionary>
</Collections:DictionaryEntry.Value>
</Collections:DictionaryEntry>
</ResourceDictionary.ThemeDictionaries>
This file was added automatically when I created a new Metro App project from the default Metro App project templates. The file compiled and ran fine before I added a IValueConverter to a page. The issue happens every time I add a IValueConverter, regardless of which project template I use, and regardless of if I add the IValueConverter using Expression Blend or Visual Studio.
This could just be a bug in the Consumer Preview release, but it seems like such a fundamental piece of work, that I figured it was worth asking here if anyone else has run into this issue and, if so, how were you able to solve or workaround it?