Visual Studio WP design inside ScrollViewer - visual-studio

I am designing an app for Windows Phone using the Viual Studio XAML designer. My page is to long to fit into a page so I had to put it inside a ScrollViewer and Grid. This works but my problem is that the designer does not allow me to see (and therefore to some extent interact) with these elements outside the page. Is there any setting or something that I can use to be able to interact with these elements?

Add the following to the XAML element of the page:
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d:DesignHeight="<desired height>"
i.e.:
<phone:PhoneApplicationPage
x:Class="PhoneApp1.MainPage"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d:DesignHeight="1600"
....more attributes...
>
<!-- other stuff -->
</phone:PhoneApplicationPage>
The xml namespace definition for "d" is probably already present, and the same can be done for the design time width, of course.

Related

Xamarin Forms - Listview - Save PDF on tap

When I click on the ListItem, which is a .PDF, in my ListView, I want to save the file locally. Each ListItem has a different Uri.
Is there any way I can do that?
Currently, it's a bit tricky to implement from scratch a ListView onTap gesture - but you can use a nuget that gives that functionality for Xamarin Forms:
http://www.michaelridland.com/xamarin/freshessentials-for-xamarin-forms-the-must-have-nuget-for-forms/
Basically, in order to use it you can just add a property to your ListView and Bind it to a Command to your CodeBehind or ViewModel (if you're following an MVVM pattern or framework):
<ListView ItemsSource="{Binding MyCars}" fe:ListViewItemTappedAttached.Command="{Binding ItemTapCommand}">
Don't forget to add this resource as property/namespace of your ContentPage tho:
xmlns:fe="clr-namespace:FreshEssentials;assembly=FreshEssentials"
Ex.
<ContentPage xmlns:fe="clr-namespace:FreshEssentials;assembly=FreshEssentials" ... />
On Saving files - Because Xamarin.Forms runs on multiple platforms, each with its own filesystem, there is no single approach for loading and saving files created by the user.
You can follow this guide from Xamarin to know how to do that for every platform you are targeting: https://developer.xamarin.com/guides/xamarin-forms/working-with/files/#Loading_and_Saving_Files

Multi-targeted WP7.1/WP8 app with Windows Phone Toolkit (Panorama / LongListSelector)

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.

Wp7 background image not showing up when i debug

I'm new to WP7 programming but have XP with other platforms, I am just running through all the basics so I can get to know the language but I have hit a roadblock I've entered a source for my background image:
<Grid x:Name="LayoutRoot">
<Grid.Background>
<ImageBrush ImageSource="C:/users/hypernova/pictures/Background1.jpg">
</ImageBrush>
</Grid.Background>
</Grid>
And the image shows up as a background in the design tab that is next to the XAML but when I debug and the emulator starts its just a black screen no background image, what have I missed? I have tried other ways of setting a background like:
<Grid x:Name="LayoutRoot">
<Canvas>
<Canvas.Background>
<ImageBrush ImageSource="C:/users/hypernova/pictures/Background1.jpg">
</ImageBrush>
</Canvas.Background>
</Canvas>
</Grid>
but the same thing happens I've tried a few other ways also but again nothing, I'm sure I've missed something I should have caught.
The path
C:/users/hypernova/pictures/Background1.jpg
exists on your dev machine, not on any Windows Phone 7+ device.
Remember, users will be downloading your app from the store, then running it on their phones. How would they possibly access your hard drive and get that image?
Unfortunately, since the design surface allows you to do this, it can of course be confusing to a new developer.
What you should do is add your image to your project as a Resource, then reference the resource via a pack URI (don't click on that link unless you want to scare yourself silly).
To add it as a resource, simply add the image to the root of your WP7 project, right click on it, select Properties, and then change the build action to Resource (not Embedded Resource, mind you).
Next, you have to construct a pack URI for this resource. This is ... not easy. You can use the tools in Visual Studio to do this, by editing the properties of your ImageBrush in the designer. This is the simplest, and recommended, route. All you have to do is edit the ImageSource of your ImageBrush in the Properties tool window, and select the image from the list of available images in the solution.
The other way is to manually construct the pack URI. For example, you could take the following
/[project assembly name];component/Background1.jpg
replace [project assembly name] with the name of your assembly (no extensions), and use it as your ImageSource value. You can find the correct project assembly name by looking at the Assembly Name under the Application section of the project properties.
<ImageBrush ImageSource="/MyWp7Application;component/Background1.jpg"/>
Note, depending on how your project folder structure is constructed, this URI may be different. Constructing the correct URI outside of the tools provided is a task deserving of another question.

Cannot create an instance of "ViewModelLocator"

I have been working fine with MVVM Light on a silverlight 4 Windows Phone 7 project in Visual Studio 2010 and Blend 4 for sometime.
Then suddenly I start getting the "Cannot create an instance of "ViewModelLocator"" error in both VS 2010 and Blend. Can't work out why it should appear now. Any ideas on how I can possibly track down if something somewhere has changed that I have not spotted.
The only change I made, and then put back, was to add a "d:" infront of the data context expression in one of the user controls. I had the idea of binding in design, but programmatically binding in a delayed manner at run time.
I see others have posted this problem, but the answers refer to a bug in Blend, which has apparently been fixed. Also this is occuring in VS2010 too.
App.xaml looks like
<Application x:Class="BillSplitter2.App"
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"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
xmlns:vm="clr-namespace:BillSplitter2.ViewModel"
xmlns:converters="clr-namespace:HardMediumSoft.WP7.Tools.Converters;assembly=HardMediumSoft.WP7.Tools">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/ResourceDictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
<!--Global View Model Locator-->
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True"/>
<!--Localization String Library-->
<local:LocalizedStrings xmlns:local="clr-namespace:BillSplitter2.Utilities"
x:Key="LocalizedStrings" />
<!--Converters -->
<converters:FloatConverter x:Key="FloatConverter" />
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
<converters:StringToBrush x:Key="StringToBrushConverter" />
</ResourceDictionary>
</Application.Resources>
<Application.ApplicationLifetimeObjects>
<!--Required object that handles lifetime events for the application-->
<shell:PhoneApplicationService Launching="Application_Launching"
Closing="Application_Closing"
Activated="Application_Activated"
Deactivated="Application_Deactivated" />
</Application.ApplicationLifetimeObjects>
Thanks to the recommendation above, I started to investigate the constructor of my ViewModel. Although I had no errors, I did find that belnd had issues with event listeners and handlers.
I was using the
if (IsInDesignMode)
{
//populate values here for blend
}
else
{
//runtime initiation
}
to populate some values for design time. I would initiate values in the model by setting their properties. This was all fine until I started adding more complex event handling routines based on property changes.
To rectify this and recover my 'blendability' I did two things!
Set private fields rather than properties in the IsDesignMode section. This avoid PropertyChanged events firing.
Added IsInDesignMode detection in event handlers that remained a problem and skipped any cascded updating.
Hope this helps!
This has previously been answered here. Verify that the issue is not an error during object instance creation (constructor, etc.)

WrapPanel for windows phone 7

I'm trying to add a WrapPanel to my app, up to now I found that WrapPanel is only available through SilverLight Toolkit here http://silverlight.codeplex.com/releases
I've downloaded it and installed it, but now what do I do?
I assumed that a reference needed to be added but I can't think of what to add.
Add a reference to Microsoft.Phone.Controls.Toolkit.dll. The WrapPanel control is in the Microsoft.Phone.Controls namespace.
In your page/user control, add the following XML namespace declaration:
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
Then you can add instances of <toolkit:WrapPanel /> in your XAML.

Resources