Debugging XAML databinding in Visual Studio 2012 - debugging

In the Silverlight 5 beta I could debug databinding directly in XAML. Where is this feature in Visual Studio 2012 (RC)? Can I do this with WPF, WinRT and/or Silverlight? If so how? When I set a breakpoint on a binding expression application, I get the message that the breakpoint will not be hit because no source code is associated with this line.
Update:
It works in Visual Studio 2012 (RC) for Silverlight 5 applications but not for WPF applications. Please don't tell me, that this feature does not exist for WPF!

Sorry to tell you but this feature DOES NOT exist in WPF XAML nor does it exist in WinRT XAML. I can't find an official source for WPF, but here is a pretty official one for WinRT (http://social.msdn.microsoft.com/Forums/en-US/toolsforwinapps/thread/fae53937-cb47-45da-b740-49f75f8d36e9/) he insinuates pretty strongly that this was an effort spearheaded purely by the Silverlight team and can possibly be expected in future versions of WPF and WinRT.
So far the best debugging techniques I've seen are as follows:
1) WinRT & WPF: Output Window
Using the output window with the proper options enabled, make sure Tools->Options->Debugging->Output Window->Data Binding = "Warning" or something else useful...
2) WinRT & WPF: Use a converter
Using a converter and just setting a break point inside the converter. Or you can build/use something similar to how WinRT XAML Toolkit does: http://winrtxamltoolkit.codeplex.com/.../WinRTXamlToolkit.Debugging/Converters/BindingDebugConverter.cs
3) WinRT: Use DebugSettings.BindingFailed
App.Current.DebugSettings.IsBindingTracingEnabled = true;
App.Current.DebugSettings.BindingFailed += (s, e) =>
{
// debug the failed binding here
};
see: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.debugsettings.bindingfailed for more information
4) WPF: Use PresentationTraceSources.TraceLevel Attached Property
Gives you a verbose output of the binding, see: http://msdn.microsoft.com/en-us/library/system.diagnostics.presentationtracesources.tracelevel.aspx for more information.
I realize this is an older question, but I couldn't find a good source of information for everything XAML, found this answer off a search engine and noticed it was still lacking an answer. It doesn't help that there are technically 3 versions of XAML going by the same moniker. So here's the dump of everything I found while investigating debugging bindings. Enjoy, hope it helps someone... -ck

Related

Customize Calendar Winrt Xaml Toolkit

I'm developing an Universal App for Win8.1, i've added the Winrt Xaml Toolkit dll but when i use Calendar control the strings of months appear only in English.
Is there any way to change them? I'm going crazy :D
PS: I've downloaded the source code of dll but there is no track of these strings
If you look at the DateTimeHelper class, you can see the method GetCurrentDateFormat which uses the en-US format. This method is used in many places for the Calendar and CalendarItem controls from the toolkit.
You can try to import the project from the site instead of using the NuGet package and then change this method to use your device locale. You can maybe change it to something like this:
public static DateTimeFormatInfo GetCurrentDateFormat()
{
return CultureInfo.CurrentCulture.DateTimeFormat;
}
I haven't tested this code so this is just a hint where you should look for your solution.

How to Migrate WP7 App to Windows 8 Metro style app

I want to migrate my Windows Phone 7 App, to a Windows 8.
I started doing it after this Documentation: http://msdn.microsoft.com/en-us/library/windows/apps/hh465136.aspx
Those are the steps:
Launch Microsoft Visual Studio Express 2012 RC for Windows 8 and create a new Metro style app using C++, C#, or Visual Basic. Choose a project template that best matches your app layout and functionality. For more info, see Jumpstart your Metro style app using templates (C#, C++, Visual Basic).
Copy the folders, code, and asset files that you want to reuse in the new project.
In the Visual Studio Solution Explorer, click Show All Files.
Select the files and folders that you copied, and then right-click them and select Include In Project.
Perform a global search and replace to replace "System.Windows" with "Windows.UI.Xaml".
Copy the reusable parts of your original XAML code into the new project's XAML files, or into newly created XAML files as necessary. You can often copy and reuse the contents of page layout roots (typically Grid elements), but not the outermost elements (typically PhoneApplicationPage elements).
My Question starts at point 2: Let's say i have a page: Settings.xaml and Settings.cs. Do i have to copy both of them or none and add the code later? If I add Settings.xaml i get an error because of the tag:
<phone:PhoneApplicationPage ...>
like it says at point 6.
I dont have any Problems with my dll's or with my "normal" classes, which arent connected to a xaml.
And when i create a Windows 8 Page i don't know where to add my Code from WP7 in Windows 8
<Grid Background="Transparent">
.....Code.....
</Grid>
I hope you guys can help me out.
I agree with ColinE, instead of copying over all the files directly, create a new Windows 8 project and copy the appropriate XAML elements and C#. If you've created separate supporting .cs files, those should copy over fine, but if your code is all together in a file, you need to figure out what methods to copy over and where to put them.
In terms of what kind of app to use (empty, grid, split, etc.) that depends on your application and its purpose. Take a look at the Designing UX for Apps article to help figure out what will work best for your app: http://msdn.microsoft.com/en-us/library/windows/apps/hh779072.
Here is another MSDN article that talks about porting a Windows Phone 7 app to a Windows 8 Metro app: http://msdn.microsoft.com/en-us/library/windows/apps/hh465136.aspx
Hope that helps!
Probably the easiest approach to tackling your XAML files is to create new usercontrols / pages in your Win8 project using Visual Studio. You can then cut and paste the XAML from WP7 to Win8 piece by piece. You can also copy across the code-behind during this process.
There are a few too many changes to make it possible to copy the XAML / cs files across directly.

CultureTypes in WP7

Hi I want to access the CultureTypes in Windows Phone. In Silverlight/WPF i can use like this,
CultureInfo[] specificCultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
But In Windows Phone it showing an error as "UnKnownEntity" in CultureTypes
Also I want to get the Id of the CurrentCulture. In Silverlight/WPF, i can use like
Thread.CurrentThread.CurrentCulture.LCID
But in Windows Phone it showing an error as "NotFound" in LCID
Could you please anyone can help me?
In Silverlight/WPF i can use like this
You can in WPF, but not in Silverlight. Look at the Silverlight version of the documentation for CultureInfo - there's no GetCultures method. I don't see any way of getting all cultures - just the current culture, current UI culture, and invariant culture. (You can create your own instances by calling the constructor, of course.)
EDIT: You've run into exactly the same problem when trying to get the LCID. You can't just assume everthing from the desktop framework will be available in Silverlight. You need to look at the Silverlight-specific documentation to see what's available (and then check that it's available on Windows Phone 7, too).
You could use T4 generator to generate missing information. I have done this for similiar problem and works great.

Could not load GestureEventArgs from System.Windows.Input

I have been searching for a solution but couldn't find any yet.
Situation is that I have a customcontrol that uses GestureEventArgs to apply some effect on the "Tap" event. The GestureEventArgs come out of the System.Windows.Input namespace. This is a WP7 (7.1) project by the way. If I use this control in an other WP7 (7.1) project my visual studio 2010 just crashes. No error or exception.
When I open the xaml file in Blend I get the following error:
TypeLoadException: Could not load type
"System.Windows.Input.GestureEventArgs" from assembly
"System.Windows.Input, version= 2.0.5.0, Culture = neutral,
PublicKeyToken=7cec85d7bea7798e"
The only cause that I see is that in the Microsoft.Phone.Controls namespace in my otherproject, also has a GestureEventArgs. But there isn't a complaint about ambiguity.
Anybody has been in this situation?
A fix would be awesome!
I ran into this when I installed and referenced the Windows Phone Silverlight Toolkit. It adds a new GestureEventsArgs to System.Windows.Controls. I got around this by aliasing my using for System.Windows.Input
using input=System.Windows.Input;

Localizing Windows Phone 7 App

I'm having a little trouble getting localized resources files to work on Windows Phone 7. Here's what I'm doing:
Create a resource file, say "Strings.resx" (Build Action: Compile)
Create a key, say "TestKey" with a default value of empty string
Add a English resource file in the same folder with a value of "some English string": Strings.en-us.resx (Build Action: Embedded Resource)
Add a Japanese resource file in the same folder with a value of "some Japanese string": Strings.ja-jp.resx (Build Action: Embedded Resource)
In my PC Silverlight, WPF Apps that works fine when I change the Thread.CurrentThread.CurrentCulture. But in the phone I always seem to be getting the value that's in the Strings.resx file - an empty string.
I have tried using the designer generated code and wiring up the resource manager by hand and it does not seem to matter. Here's my code:
Type t = typeof(Strings);
_resourceManager = new ResourceManager(
t.Namespace + "." + t.Name,
t.Assembly);
_resourceManager.GetString("TestKey");
Tell me localized resources are supported on the phone... ;> What am I doing wrong? Thanks!
Update: Thanks Olivier for forwarding the link. I saw that as well but missed an important step. I didn't add the "SupportedCultures" node to my csproj. Made all the difference - hoping someone else doesn't loose two hours trying to figure this out like I did.
<SupportedCultures>de-DE;es-ES;</SupportedCultures>
Of course, localized resources are supported on the phone:
How to: Build a Localized Application for Windows Phone
I wrote a blog post that provides links to a bunch of Globalization / Localization guides for WP7. There is a Windows Phone 7 in 7 Training video that helped me understand the basics. After that it was simply a matter of learning how to do databinding:
The MSDN article shows you how to
setup the files and create the
LocalizedStrings class, but they then
assume that you know how to use that
class for data binding. Visual Studio
2010 and Silverlight handle data
binding differently than Winforms, and
it gets even more confusing since XAML
also has it’s own definition of
Resources that are different then the
.NET resources we just created.
Silverlight also uses the term
Resource to refer to files that use
the the Build Action of "Content”, as
these files get wrapped up into the
.XAP file similar to how files with
Build Action of "Resource” get
embedded into the .Dll assembly (ex:
loading an image from content or
resource files). I found that instead
of using the Text="{Binding
Path=resourceFile.resourceName,
Source={StaticResource
Localizedresources }}" XAML syntax it
was easier to use the following steps:
Open your primary XAML page (usually MainPage.xaml) in the Visual
Studio designer
Open the properties for the PhoneApplicationPage and set the
DataContext to be
Application.Resources –>
LocalizedStrings. NOTE: if you already
are using a DataContext object, then
you should integrate the
LocalizedStrings class into that
object so that it has localization
support.
Once the Page’s DataContext has been set you can change the data
binding for any control on the page by
simply selecting the property (ex:
text, checked, etc), selecting “Apply
Data Binding…”, and setting the Path
to Localizedresources.BtnText or
whatever the name of the desired
resource value is.

Resources