Prism not working in WP7.1 but working in WP8 - silverlight

I have developed a Windows Phone application using MVVM (Prism v4.1).
Everything is working fine when I deploy it to the Emulator WVGA or my HTC 8X but when I deply it to my Lumia 800 or use the Emulator 7.1 it isn't working.
Here is one part of the view(model) hope it helps a bit
View
<phone:PhoneApplicationPage
x:Class="LearnByTranslate.Views.PhrasePracticeView"
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:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
xmlns:converter="clr-namespace:LearnByTranslate.Infrastructure.Convverters"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
<Grid x:Name="LayoutRoot" Background="Transparent">
<ScrollViewer Margin="24,0,24,72" Grid.Row="1">
<StackPanel x:Name="stkPracticeContent" Margin="0">
<TextBlock x:Name="txtTextToTranslate" HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding EnglishPhrase,Mode=TwoWay}" FontSize="40" FontStyle="Normal" VerticalAlignment="Top" Style="{StaticResource EnglishSentenceStyle}" FontFamily="Segoe WP Light">
<TextBlock.Foreground>
<SolidColorBrush Color="{StaticResource PhoneForegroundColor}"/>
</TextBlock.Foreground>
</TextBlock>
</StackPanel>
</ScrollViewer>
</Grid>
</phone:PhoneApplicationPage>
ViewModel
class PhrasePracticeViewModel : NotificationObject
{
private string _englishPhrase;
public PhrasePracticeViewModel()
{
}
public string EnglishPhrase
{
get { return _englishPhrase; }
set
{
_englishPhrase = value;
RaisePropertyChanged(() => EnglishPhrase);
}
}
}
Everything is working fine (regarding the binding in the other views) except for this view.
Any ideas?

This is one of the strangest things I have ever seen.
The reasone for this was that my ViewModel class wasn't made public (as you can see above). I'll look into this a little deeper why this works on WP8 but not on WP7.1 but it really frustrated me.
Hope this helps someone else.

Related

WPF - DataBinding (Command is not being executed)

I am writing a WPF application where I wish to implement the MVM pattern.
My code is currently set up like this:
This is my view model class where I am exposing the command I wish to be executed as a property
```
public HomeScreenViewModel(NavigationService mw)
{
this.mw = mw;
}
private RelayCommand _addStudent;
public ICommand AddStudent
{
get
{
if (_addStudent == null)
{
_addStudent = new RelayCommand(param => this.OpenNewStudents(), param => true);
}
return _addStudent;
}
}
This is my xaml containing the layout of the corresponding view
<Page x:Class="test.HomeScreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:test"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="1300"
Title="HomeScreen">
<WrapPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<WrapPanel HorizontalAlignment="Center" Height="300" Margin="0,0,0,0" VerticalAlignment="Center" Width="1300">
<Button Content="AddStudent" Command="{Binding AddCommand}" Style="{StaticResource ButtonStyle}" />
<Button Content="AddStudent" Style="{StaticResource ButtonStyle}" />
<Button Content="AddStudent" Style="{StaticResource ButtonStyle}" />
<Button Content="AddStudent" Style="{StaticResource ButtonStyle}" />
<Button Content="AddStudent" Style="{StaticResource ButtonStyle}" />
<Button Content="AddStudent" Style="{StaticResource ButtonStyle}" />
<Button Content="AddStudent" Style="{StaticResource ButtonStyle}" />
<Button Content="AddStudent" Style="{StaticResource ButtonStyle}" />
<TextBox Text="{Binding Path=HI}" Width="200" Height="200"/>
</WrapPanel>
<Canvas Margin="350, 100,0, 0" Height="300" Width="1350" VerticalAlignment="Center" HorizontalAlignment="Center">
<Image Source="Logo.PNG"/>
</Canvas>
</WrapPanel>
I have set the command of the top button using the binding syntax in the WrapPanel.
This HomeScreen page is linked from a naviagation window and is the source of the navigation window (xaml file):
<NavigationWindow x:Class="test.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"
xmlns:local="clr-namespace:test"
mc:Ignorable="d"
Title="School Management App" Height="350" Width="1250"
Source="HomeScreen.xaml">
</NavigationWindow>
I have my HomeScreen view constructor set like this:
public partial class HomeScreen : Page
{
public HomeScreen()
{
InitializeComponent();
this.DataContext = new HomeScreenViewModel(this.NavigationService);
}
}
My infrastructure is set up as I have described above and my implementation of relay command is taken from this site https://msdn.microsoft.com/en-us/magazine/dd419663.aspx.
When I run my application and I press the corresponding button, nothing happens. I was wondering if someone could help me figure out what is wrong and why the command binding isn't working. It would be much appreciated, thanks :)
as a side note, could someone give me some tips on what the best way to debug wpf applications and figure out what bindings exist at run time.
Thanks :)
your command name is AddStudent, but you use AddCommand in xaml. Just correct the name:
Command="{Binding AddStudent}"

Why does this Microsoft.VisualStudio.Imaging.CrispImage does not show anything?

I am trying to create a very simple WPF application to experiment this concept of the Visual Studio Image Service and Catalog.
I don't understand why I cannot seem to be able to show any of the known images (using KnownMonikers) both on the WPF designer or when the app runs.
The image is there. It just does not show anything.
Here's the WPF source code (following exactly the steps described in the MSDN link above):
<Window x:Class="ImageCatalogBrowser.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"
xmlns:local="clr-namespace:ImageCatalogBrowser"
xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging"
xmlns:theming="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Imaging"
xmlns:utilities="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Utilities"
xmlns:catalog="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.ImageCatalog"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<utilities:BrushToColorConverter x:Key="BrushToColorConverter"/>
</Window.Resources>
<Grid>
<StackPanel
Background="White"
VerticalAlignment="Center"
theming:ImageThemingUtilities.ImageBackgroundColor="{Binding Background, RelativeSource={RelativeSource Self}, Converter={StaticResource BrushToColorConverter}}">
<Border BorderThickness="1" BorderBrush="Black" Width="33" Height="33">
<imaging:CrispImage
x:Name="crisp"
Visibility="Visible"
Width="32"
Height="32"
Moniker="{x:Static catalog:KnownMonikers.Save}" />
</Border>
</StackPanel>
</Grid>
</Window>
Can anyone help please?
What's your code-behind doing to initialize the ImageLibrary? If the library cannot find the moniker you're requesting, then it won't display the image.
Make sure when initializing the ImageLibrary you give it the path to the ImageCatalog's .imagemanifest file (in the VS install dir).

Binding example

I have been trying for weeks to find a decent article that explains WPF Binding simply and with a working example that actually explains what is happening. Yes there are lots of examples out there but lots of those refer to older versions of everything involved.
I am trying to write an application, that is not web based, uses WPF and VB on VS2012.
In this bit of code i am updating a screen field directly, but i want to learn how to update a variable in memory and it update on the screen automatically, how do i get from here to there - In stages with explanations
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Test Bind"
Height="299" Width="500" WindowStartupLocation="CenterScreen">
<DockPanel HorizontalAlignment="Stretch" LastChildFill="False" VerticalAlignment="Stretch">
<DockPanel DockPanel.Dock="Top" Height="64">
<Button Content="Button" Height="64" VerticalAlignment="Top" Width="75" Click="Button_Click" />
<TextBox Height="64" Width="120" Text="TextBox1" x:Name="clickcount" />
<TextBox Height="64" Width="120" x:Name="textBox2" Text="{Binding Test, Mode=Default}" />
</DockPanel>
</DockPanel>
</Window>
Class MainWindow
Public Shared clcount As Integer = 0
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
clcount = clcount + 1
Me.clickcount.Text = clcount.ToString
End Sub
End Class

wp7 popup blocking textbox in popup

I have a popup that opens on the MainPage with a couple of textboxes. When ever you focus on the lower textbox the keyboard obscures it from view. Usually the textboxes slide into view. i don't know why that is not happening here.
please help!
<UserControl x:Class="Controls.EditControl"
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"
xmlns:SampleData="clr-namespace:SampleData"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
Height="800" Width="480"
d:DataContext="{d:DesignData ../SampleData/sampleEditPopup.xaml}">
<Grid x:Name="LayoutRoot" Background="#FF000000" Opacity="0.995">
<StackPanel Margin="0,20,0,0" Orientation="Horizontal" VerticalAlignment="Top">
<TextBlock TextWrapping="Wrap" Text="Name" HorizontalAlignment="Left" Height="26" Margin="15,10,0,10" Width="110" TextAlignment="Right"/>
<TextBox x:Name="tb_name"
TextWrapping="Wrap"
Width="340" Height="75"
Margin="10,13,15,12"
InputScope="Text" MaxLength="1000"
Text="{Binding Title, Mode=TwoWay}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,150,0,0" VerticalAlignment="Top">
<TextBlock TextWrapping="Wrap" Text="Description" HorizontalAlignment="Left" Height="26" Margin="15,40,0,10" Width="110" VerticalAlignment="Top" TextAlignment="Right"/>
<TextBox x:Name="tb_description"
TextWrapping="Wrap"
Width="340" Height="254"
Margin="10,13,15,12"
InputScope="Text" MaxLength="1000"
Text="{Binding Description, Mode=TwoWay}"/>
</StackPanel>
</Grid>
and here is the code to open it:
EditControl ec = new EditControl();
ec.Title = cm.Title;
ec.Description = cm.Description;
//sets appbar icons for accepting values
setEditIcons();
Popup edit = new Popup() { Child = ec, Tag = this };
edit.Closed += new EventHandler(edit_Closed);
edit.IsOpen = true;
from a UX perspective I'd heavily recommend against having any partial popup/overlay that has more than 1 or 2 buttons. It's just not done in WP7. If you have a form you'd like folks to fill out move it to its own page. Either by letting the user navigate to that page, or by introducing a new transient page (that cannot be navigated back into) prior to the current page.
You'll have more problems than just the on-screen keyboard in with form overlays. You'll need to change the AppBar to have "V" and "X" buttons for any data entry, you'll need to manage focus not slipping back into under the overlay/popup, you'll need to make sure the "back" button closes the popup, etc.
IMO The best approach is a simple and consistent UX.

Multi-touch ScrollViewer eating touch events

WPF 4.0:
I have scroll viewer with many Sliders inside of it. I want the scroll viewer to pan with touch, and I want the internal slider to also respond to touch.
Unfortunately, the scroll viewer is eating the "TouchMove" events and not passing them down to the slider control. Any idea how to fix this?
Here is my XAML:
<Window x:Class="ScrollingTest.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>
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.Template>
<ControlTemplate>
<ScrollViewer VerticalScrollBarVisibility="Auto" PanningMode="Both" >
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Height="100" BorderThickness="2" BorderBrush="Black">
<Slider Value="{Binding ., Mode=TwoWay}" Width="300" Minimum="0" Maximum="100" />
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Window>
And my Code-behind:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = Items;
}
public IEnumerable<int> Items
{
get
{
return Enumerable.Range(0, 50);
}
}
}
Please see my answer to this question: ScrollViewer in a touch interface not working properly
I just resolved this issue in our app as well using a custom Thumb control - in my answer I explain what is causing the problem.
This sounds like a case of "routed event marked as handled". Can you try using AddHandler to subscribe to that event, and set the last parameter "handledEventsToo" to true?
Cheers,
Laurent
It's handling the TouchMove event, most likely. There are bubbling events (PreviewTouchMove, etc) you could handle in your Slider control. You would need to coordinate how you want the touch events to be handled.
You can try to make your custom class, derived from ScrollViewer and override OnTouchMove method.
public class CustomScrollViewer : System.Windows.Controls.ScrollViewer
{
protected override void OnTouchMove(System.Windows.Input.TouchEventArgs e)
{
// delete the base.OnTouchMove() call to prevent event being "eat" :)
}
}
Then, you edit the xaml like this:
<Window x:Class="ScrollingTest.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>
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.Template>
<ControlTemplate>
<local:CustomScrollViewer VerticalScrollBarVisibility="Auto" PanningMode="Both" >
<ItemsPresenter />
</local:CustomScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Height="100" BorderThickness="2" BorderBrush="Black">
<Slider Value="{Binding ., Mode=TwoWay}" Width="300" Minimum="0" Maximum="100" />
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Window>

Resources