I've just started using the Expensify Windows Phone Test Framework and it seems to fit my requirements for automated testing of Windows Phone 7.1 quite well. I can get it to trigger a normal button on the screen but cannot get it to trigger either of my ApplicationBar buttons.
The XAML for this test page is ...
<phone:PhoneApplicationPage x:Class="SampleApp1.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"
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:AppBarUtils="clr-namespace:AppBarUtils;assembly=AppBarUtils"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait"
Orientation="Portrait"
mc:Ignorable="d"
d:DesignWidth="480"
d:DesignHeight="768"
shell:SystemTray.IsVisible="True"
DataContext="{Binding Main, Source={StaticResource Locator}}">
<!--LayoutRoot contains the root grid where all other page content is placed-->
<Grid x:Name="LayoutRoot"
Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel"
Grid.Row="0"
Margin="24,24,0,12">
<TextBlock x:Name="ApplicationTitle"
Text="{Binding ApplicationTitle}"
Style="{StaticResource PhoneTextNormalStyle}" />
<TextBlock x:Name="PageTitle"
Text="{Binding PageName}"
Margin="-3,-8,0,0"
Style="{StaticResource PhoneTextTitle2Style}" />
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentGrid"
Grid.Row="1">
<StackPanel Margin="24,20,0,123" Orientation="Vertical">
<TextBlock Text="{Binding Welcome, Mode=OneWay}"
Style="{StaticResource PhoneTextNormalStyle}"
HorizontalAlignment="Center" VerticalAlignment="Center"
Margin="6,0,19,0" TextWrapping="Wrap" Width="431" />
<TextBlock Text="Enter first number"
HorizontalAlignment="Left" VerticalAlignment="Top"
Margin="6,20,0,0" TextWrapping="Wrap" />
<TextBox TextChanged="OnTextBoxTextChanged"
Text="{Binding EnteredAmount1, Mode=TwoWay, UpdateSourceTrigger=Explicit}"
x:Name="txtValue1"
HorizontalAlignment="Left" Height="72" VerticalAlignment="Top" Width="456"
TextWrapping="Wrap" InputScope="Number"/>
<TextBlock Text="Enter second number"
HorizontalAlignment="Left" VerticalAlignment="Top"
Margin="6,0,0,0" TextWrapping="Wrap" />
<TextBox TextChanged="OnTextBoxTextChanged"
Text="{Binding EnteredAmount2, Mode=TwoWay, UpdateSourceTrigger=Explicit}"
x:Name="txtValue2"
HorizontalAlignment="Left" Height="72" VerticalAlignment="Top" Width="456"
TextWrapping="Wrap" InputScope="Number"/>
<TextBlock Text="Result"
HorizontalAlignment="Left" VerticalAlignment="Top"
Margin="6,20,0,0" TextWrapping="Wrap"/>
<TextBlock Text="{Binding Total, Mode=OneWay}"
HorizontalAlignment="Left" VerticalAlignment="Top"
Margin="15,0,0,0" TextWrapping="Wrap"
Width="422" Height="45"/>
<Button x:Name="btnAdd" Command="{Binding AddCommand}" Content="Add" Margin="240,0,0,0" />
</StackPanel>
</Grid>
</Grid>
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="False">
<shell:ApplicationBarIconButton x:Name="AddAppBarBtn" IconUri="/Images/ApplicationBar.Check.png" Text="add"></shell:ApplicationBarIconButton>
<shell:ApplicationBarIconButton x:Name="SubtractAppBarBtn" IconUri="/Images/ApplicationBar.Cancel.png" Text="subtract"></shell:ApplicationBarIconButton>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
<i:Interaction.Behaviors>
<AppBarUtils:AppBarItemCommand Id="add" Command="{Binding AddCommand}"/>
<AppBarUtils:AppBarItemCommand Id="subtract" Command="{Binding SubtractCommand}"/>
</i:Interaction.Behaviors>
<i:Interaction.Triggers>
<AppBarUtils:AppBarItemTrigger Type="Button" Id="add" Text="add" />
<AppBarUtils:AppBarItemTrigger Type="Button" Id="subtract" Text="subtract" />
</i:Interaction.Triggers>
</phone:PhoneApplicationPage>
The SpecFlow features are defined as follows ...
Scenario: AppBar Add Two Numbers
Given my app is uninstalled
And my app is installed
And my app is running within 20 seconds
Then I enter "34" into the control "txtValue1"
Then I enter "23" into the control "txtValue2"
Then I press the control "AddAppBarBtn"
Scenario: Button Add Two Numbers
Given my app is uninstalled
And my app is installed
And my app is running within 20 seconds
Then I enter "34" into the control "txtValue1"
Then I enter "23" into the control "txtValue2"
Then I press the control "btnAdd"
The ButtonAddTwoNumbers scenario fully works. The AppBarAddTwoNumbers fills in the text box values but refuses to press the button, The error I get is "Failed to set focus to control 'AddAppBarBtn'".
Any help on this would be appreciated.
I think you are working one level too high. Personally I wouldn't normally test the UI itself as in the long term it just leads to brittle tests that constantly need changing. Instead I would normally come down to the ViewModels.
So given that your txtValue1 is bound to EnteredAmount1, txtValue2 is EnteredAmount2 and AddAppBarBtn is AddCommand, you can test your business logic as
Scenario: AppBar Add Two Numbers
Given I enter 34 into Amount1
And I enter 23 into Amount2
When I add them #Calls AddCommand
Then Total should be 57
This means that you can redesign your UI very easily, so say for example if we wanted to use sliders instead of textboxes, there would be NO changes to the above logic tests.
In addition you can still test your UI features as seperate features
Scenario: Check startup
Given my app is uninstalled
When my app is installed
Then my app should be running within 20 seconds
And if you really want you can still check your bindings too
Scenario: Check bindings
Given I enter 34 into Amount1
Then control txtValue1 should be 34
In this way you'll break your tests into smaller chunks of the application and give yourself more targetted failures, which is really useful when tracking down any problems.
Related
This is a bit of a tricky question to put succinctly but here goes. Snippets have been included to get the point across.
This problem came about whilst trying to solve another problem, to which a solution was found on SO, but which required to right-click and edit the default style of a TextBox, which I can't do because the TextBox in question is part of a DataTemplate on a databound ListView which of course has no content at design time.
Here are some snippets: I use a data template to control the content/layout of my listview like so:
<ListView x:Name="DataItemList"
ItemsSource="{x:Bind MasterMenuItem.DataObjects, Mode=OneWay}"
SelectedItem="{x:Bind SelectedItem, Mode=TwoWay}"
SelectionMode="Single"
ItemTemplate="{StaticResource DataListItemTemplate}">
</ListView>
and a data template as a page/control resource
<DataTemplate x:Key="DataListItemTemplate" x:DataType="vm:DataObjectListItem">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
<Grid Height="40" Margin="10 0 0 0">
<Grid.Resources>
<SolidColorBrush x:Key="brush" Color="Silver"/>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40" />
<ColumnDefinition Width="*" MinWidth="240" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0" BorderBrush="{StaticResource brush}" BorderThickness="1 1 1 1">
<FontIcon Name="Icon"
Grid.Column="0"
VerticalAlignment="Center"
FontSize="32"
Glyph="{x:Bind ListItemIcon}" />
</Border>
<Border Grid.Column="1" BorderBrush="{StaticResource brush}" BorderThickness="1 1 1 1">
<TextBlock Name="Data Object Name"
Padding="6 4 6 4"
Text="{x:Bind Name, Mode=OneWay}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontWeight="Bold"
TextWrapping="WrapWholeWords"/>
</Border>
</StackPanel>
</DataTemplate>
When I view my page in the Design tab of visual studio (instead of the XAML tab) I see nothing useful, unlike if, for example, I put a TextBlock in my XAML with Text="Hello" I would be able to see 'Hello' in the Design tab and crucially Right-Click on it to do certain things...
Is there a way to 'populate' the list with some dummy data, or the text box with some dummy text in order to visualize the runtime layout in the Design tab?
I have Silverlight based web app where. I found the ListBox doesn't scroll on mouse wheel scroll. I am able to scroll by clicking vertical scroll bar. When I use mouse wheel or 2 finger scroll it doesn't work.
Here in Mouse Wheel scroll in List box 2 is working fine but ListBox 1 it does not work.
ListBox 1
<Border CornerRadius="6,6,0,0" Grid.Row="1" Margin="2,5,2,0" BorderThickness="1,1,1,0" BorderBrush="#FFC4C4C4">
<Grid>
<ListBox x:Name="filterListBox" Grid.Row="0" Grid.Column="1" Background="Transparent" SelectedIndex="{Binding SelectedFilterIndex, Mode=TwoWay}" SelectedItem="{Binding SelectedFilterItem, Mode=TwoWay}" SelectionChanged="ListBox_SelectionChanged" BorderThickness="0" VerticalAlignment="Center" Margin="5,3" ItemContainerStyle="{StaticResource FilterListBoxItemStyle}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<ei:CallMethodAction TargetObject="{Binding}" MethodName="FilterSelectionChanged"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBoxItem Padding="7,2" VerticalContentAlignment="Center" Tag="Popular" Visibility="{Binding Path=IsPopularChannelTab, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}}">
<TextBlock Text="{Binding Path=PopularChannelsText, Source={StaticResource PageStrings}}" FontSize="13" FontWeight="SemiBold" FontFamily="Arial" VerticalAlignment="Center" />
</ListBoxItem>
<ListBoxItem IsEnabled="False" VerticalContentAlignment="Center" Visibility="{Binding Path=IsPopularChannelTab, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}}">
<StackPanel Orientation="Horizontal">
<Border BorderBrush="#FFBDBDBD" BorderThickness="0,2,2,2" HorizontalAlignment="Center" VerticalAlignment="Center" Height="20"/>
<Border BorderBrush="#FFF8F8F8" BorderThickness="0,2,2,2" HorizontalAlignment="Center" VerticalAlignment="Center" Height="20"/>
</StackPanel>
</ListBoxItem>
<ListBoxItem Padding="7,2" VerticalContentAlignment="Center" Tag="All">
<TextBlock Text="{Binding Path=AllChannelsText, Source={StaticResource PageStrings}}" FontSize="12" FontWeight="SemiBold" FontFamily="Arial" VerticalAlignment="Center"/>
</ListBoxItem>
<ListBoxItem IsEnabled="False" VerticalContentAlignment="Center">
<StackPanel Orientation="Horizontal">
<Border BorderBrush="#FFBDBDBD" BorderThickness="0,2,2,2" HorizontalAlignment="Center" VerticalAlignment="Center" Height="20"/>
<Border BorderBrush="#FFF8F8F8" BorderThickness="0,2,2,2" HorizontalAlignment="Center" VerticalAlignment="Center" Height="20"/>
</StackPanel>
</ListBoxItem>
<ListBoxItem Padding="7,2" VerticalContentAlignment="Center" Tag="Favorites">
<TextBlock Text="{Binding Path=FavoritesText, Source={StaticResource PageStrings}}" FontSize="13" FontWeight="SemiBold" FontFamily="Arial" VerticalAlignment="Center"/>
</ListBoxItem>
</ListBox>
</Grid>
</Border>
ListBox 2
<Grid Visibility="{Binding Path=IsHavingProvider, Converter={StaticResource BoolToVisibilityConverter}}" Margin="0,20,0,0" Grid.Row="4">
<Grid.RowDefinitions>
<RowDefinition Height="18"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<core:MagicTextBlock Grid.Row="0" TextBlockStyle="{StaticResource TextBlock_Style}" Text="{Binding Path=Activity, Source={StaticResource PageStrings}}" />
<ListBox Margin="0,10,0,0" Grid.Row="1" x:Name="Provider" Width="480" Height="195" HorizontalAlignment="Left" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ItemsSource="{Binding Providers,Mode=TwoWay}"
SelectedItem="{Binding SelectedProvider,Mode=TwoWay}"
ItemContainerStyle="{StaticResource Table_ListBoxItem_Style}"
DisplayMemberPath="name">
</ListBox>
</Grid>
Sorry to be the bearer of bad news:
Some current mouse devices for Macintosh have a physical or virtual
mouse wheel. However, the program access layer used by Silverlight on
Macintosh does not support forwarding the mousewheel event to
Silverlight in a browser-hosted situation. You can handle the
Silverlight MouseWheel event from a Macintosh platform client, if the
Silverlight application is running out-of-browser. Otherwise, consider
handling mousewheel events for Macintosh platform at the HTML DOM
level; for more information, see Platform Dependencies.
From the MSDN Silverlight Differences on Windows and Macintosh.
The good news is you can listen to the mousewheel events in the HTML page via JavaScript and pass those events into Silverlight via its JavaScript interop API. The additional bad news is I don't know of a way to have it automatically wire into the GUI elements in your application to have them automatically just work (like scrolling list boxes in your case). As far as I know, you'd have to manually listen to it, pick up on which object the user is hovering over with their mouse, and programmatically scroll the GUI component.
Not being at all familiar with XAML, I'm trying to get a very simple layout designed where the main page consists of two parts:
On the left, I want an image that will scale to fit the available height but maintain its aspect ratio.
On the right, I want a panel that will eventually contain text and controls - at the moment I just have text.
I can get the image to behave ok by using a ViewBox but I can't seem to get the right side of the screen to fill the remaining gap. See screenshot:
What I want is for the area that contains the text to stretch to the right with the text centred within it.
The relevant XAML code is:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<StackPanel Orientation="Horizontal">
<Viewbox HorizontalAlignment="Right">
<Image Source="Assets/ABCImage.png"></Image>
</Viewbox>
<StackPanel Orientation="Vertical">
<TextBlock Text="ABC Viewer"
TextAlignment="Center"
FontSize="48"></TextBlock>
<TextBlock Text="Test application"
TextAlignment="Center"
FontSize="24"></TextBlock>
</StackPanel>
</StackPanel>
</Grid>
This is taking me far too long to figure out. Can someone please put me out of my misery?
Try this :
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Viewbox Grid.Column="0"
HorizontalAlignment="Right">
<Image Source="Assets/ABCImage.png"></Image>
</Viewbox>
<StackPanel Grid.Column="1">
<TextBlock Text="SEM Viewer"
TextAlignment="Center"
FontSize="48" />
<TextBlock Text="Test application"
TextAlignment="Center"
FontSize="24" />
</StackPanel>
</Grid>
I tried to control the memory in our application. But the memory is not the same as when a new application starts.
Example:
In app, I have 2 Pages (MainPage.xaml and Page1.xaml).
Code in MainPage(.Xaml):
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button Content="Button" Height="72" HorizontalAlignment="Left" Margin="147,223,0,0" Name="button1" VerticalAlignment="Top" Width="160"/>
</Grid>
</Grid>
and Page1.xaml :
<Grid x:Name="LayoutRoot" Background="Transparent">
<Button Content="add" Height="72" HorizontalAlignment="Left" Margin="41,12,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
<Button Content="remove" Height="72" HorizontalAlignment="Left" Margin="240,12,0,0" Name="button2" VerticalAlignment="Top" Width="160" Click="button2_Click" />
<ListBox Height="666" HorizontalAlignment="Left" Margin="12,90,0,0" Name="lsbMyList" VerticalAlignment="Top" Width="456" />
</Grid>
Page1: when I returned from the memory MainPage, my application increased from 1Mb to over 5Mb.
In listbox of Page1, I add an Image to listBox, when I Back Page , I set the image control to null URL and imageControl = null; memory is not reduced
Can anyone point me in the right direction?
See instructions on releasing image memory at http://blogs.msdn.com/b/swick/archive/2011/04/07/image-tips-for-windows-phone-7.aspx
How are you confirming that the memory is from the image and not anything else you're using and possibly not clearing up?
I'm looking to create a control that is similar to the "bubble" textbox found in the default SMS app. I was able to come close, creating a "bubble" shaped path, with a textbox inside it, but am having issues with the textbox sizing. I have set "AcceptsReturn" on the textbox to True. What I've noticed is that when the number of lines in the textbox increases, the textbox disappears from the view (under the SIP). This is not the way the SMS textbox behaves - it always seems to scroll up to show the latest line (whereas my control becomes hidden). Would appreciate any pointers...
[Update]
Managed to create this by customizing TextBox template:
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Rectangle Grid.Row="1" StrokeThickness="0" Fill="{TemplateBinding Background}"/>
<ContentControl Grid.Row="1" x:Name="ContentElement" HorizontalContentAlignment="Stretch" Margin="0" Padding="{StaticResource PhoneTouchTargetLargeOverhang}" VerticalContentAlignment="Stretch" FontSize="{StaticResource PhoneFontSizeNormal}" Background="Black" />
<Path Data="M161.25,90.75 L184.25,90.75 L184.25,100.75" HorizontalAlignment="Left" Grid.Row="0" Stretch="Fill" StrokeThickness="0" UseLayoutRounding="False" Width="23" RenderTransformOrigin="0.5,0.5" Fill="{TemplateBinding Background}" Margin="54.75,0,0,0">
<Path.RenderTransform>
<CompositeTransform Rotation="180"/>
</Path.RenderTransform>
</Path>
<Rectangle Grid.Row="2" Fill="{TemplateBinding Background}"/>
<TextBlock x:Name="txtTimeStamp" Grid.Row="2" TextWrapping="Wrap" Padding="{TemplateBinding Padding}" FontSize="{StaticResource PhoneFontSizeSmall}" Text="{Binding Timestamp, Converter={StaticResource dateTimeConverter}, Mode=TwoWay}">
<TextBlock.Foreground>
<SolidColorBrush Color="{StaticResource PhoneTextBoxForegroundColor}"/>
</TextBlock.Foreground>
</TextBlock>
</Grid>