ArgumentException thrown in system OnTouch event - windows-phone-7

I have a simple application with two pages on it. The first page acts normally, and I have a button on the page that navigates to the second page.
However, when I get to the second page, any time I try to touch anything, the OnTouch event fires and an ArgumentException is thrown in the ListDictionaryInternal
However, I have nothing on the page that interacts with this OnTouch event, so I'm not sure what could be causing it.
The code to navigate to the new page:
string page = "valid";
NavigationService.Navigate(
new Uri("/Dialog.xaml?page=" + page,
UriKind.Relative)
);
The XAML of the page that crashes is very simple:
<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 Grid.Row="0" Margin="12,17,0,28">
<TextBlock Name="AppName" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Name="PageName" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle2Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button Click="CancelDownload_Click" Opacity="1.0" Content="Cancel REST Request!" Background="Blue" Foreground="White" BorderBrush="Black" FontWeight="Bold" BorderThickness="1" x:Name="CancelData" VerticalAlignment="Center" Margin="90,327,90,291" Height="150" Width="300" Visibility="Collapsed" />
</Grid>
</Grid>
What could be causing the OnTouch to fail in such a way?
Thank you for any help.

As it turns out, thee was a hack from the main page I had used to disable the scrolling of PivotItems when interacting with a nested Panorama.
The code that caused the error:
Touch.FrameReported += (s, e) =>
{
if (e.GetPrimaryTouchPoint(MainItems).Action == TouchAction.Up)
{
MainItems.IsHitTestVisible = true;
}
};

Related

CollectionView Xamarin How to speed rendering

I have a list to show where we show repeat information from SQlite database to user. In this we show basically the product price, name and type. Usually a user will have 10-15 of such records.
Problem is it take 10+ sec to display the list. Now, the architecture of application. On page load of Shell application we fetch the information from web request and store that in SQlite and then Bind the Result from Sqlite StackLayout with Bindable Property. But it took more than 10-11 Sec to display us.
So we change it to Grid with Bindable property and results are same. Though I don't like CollectionView (as I found their select property weird. ) We use CollectionView with dataTemplate as Grid (as we have some tabular information to show) . The results still take same 10+ secs to load up.
i.e. I use Stacklayout, Grid, CollectionView, it take that much time. We are not using the ObservableCollection to bind, but our class elements are all INotifyPropertyChanged. So, I try to disable it but still even when I do not inherity INotifyPropertyChanged and remove "OnPropertyChanged" calls it still take same time.
However, when I reduce the information to just show the name of product (through binding) it reduce to 5 secs. Which is still a lot as a Collection View with just 10 records and showing one Bindable Grid showing result in 5 second is lot more than expected. I understand my other data (which call functions) maybe slowing it down but can we reduce those 5 second somehow?
I cannot share much of class, but some of properties are pretty straight forward Property with INotifyPropertyChange on string or int values.
Here is Code for loading CollectionView
public async Task LoadSearch()
{
CurrentState = LayoutState.Loading;
try
{
var o = await PatientMedicine.FetchPatientMedicine();
if (o)
{
var _sr = (await DBCoreAsync.GetDataAsync<PatientMedicine>())?.OrderBy(x => x.PatientMedID).ToList();
if (_sr != null)
{
SearchResults = _sr;
}
CurrentState = LayoutState.Success;
}
else
{
CurrentState = LayoutState.Error;
}
}
catch (Exception ex)
{
CurrentState = LayoutState.Error;
}
}
Here is Collection itself.
<CollectionView ItemsSource="{Binding SearchResults}" ItemSizingStrategy="MeasureFirstItem">
<CollectionView.ItemsLayout>
<LinearItemsLayout Orientation="Vertical" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid Padding="0,7" ColumnSpacing="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<BoxView BackgroundColor="{Binding LowStock, Converter={StaticResource BoolToColorReverse}}" CornerRadius="5,0,5,0" />
<Grid Grid.Column="1" Margin="0"
Padding="10,5" BackgroundColor="{StaticResource PrimaryLight2}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="40" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Image Grid.Column="0" Grid.Row="0" Source="{Binding Medicine.RxIcon}" ></Image>
<Label Grid.Column ="1" Grid.Row="0" Style="{StaticResource GeneralLabelBlack}" Text="{Binding Medicine.MedicineName}"></Label>
<Button Grid.Column="2" Grid.Row="0" Command="{Binding Path=BindingContext.NavigateToMedicineReminder, Source={x:Reference Name=MedicineListPageName}}" CommandParameter="{Binding .}"
BackgroundColor="Transparent" VerticalOptions="Center" HorizontalOptions="End" ImageSource="{FontImage FontFamily=FontAwesomeSolid, Glyph=, Color={StaticResource Primary},Size=16}" ></Button>
<Image Grid.Column="0" Grid.Row="1"
Source="{StaticResource ImageSourceIconClockOpenHand}"></Image>
<Label Grid.Column ="1" Grid.Row="1" Text="{Binding RepeatStatusFormatted}"></Label>
<Image Grid.Column="0" Grid.Row="2"
Source="{StaticResource ImageSourceIconStock}"></Image>
<Label Grid.Column ="1" Grid.Row="2" Text="{Binding StockAndRequirement}"></Label>
<Image Grid.Column="0" Grid.Row="3"
Source="{StaticResource ImageSourceIconClock}"></Image>
<Label Grid.Column ="1" Grid.Row="3" Text="{Binding NextReminder}"></Label>
<Label Grid.Column ="0" Grid.Row="4" Grid.ColumnSpan="2" Text="{Binding Medicine.AilmentString}"></Label>
<Label Grid.Column ="0" Grid.ColumnSpan="2" Grid.Row="5" IsVisible="{Binding LowStock}" Text="Stock running low. Order a refill now" HorizontalOptions="End"></Label>
<Button Grid.Column="2" Grid.Row="5" Command="{Binding Path=BindingContext.AddtoCart, Source={x:Reference Name=MedicineListPageName}}" CommandParameter="{Binding .}"
BackgroundColor="Transparent" IsVisible="{Binding LowStock}" VerticalOptions="Center" HorizontalOptions="End" ImageSource="{FontImage FontFamily=FontAwesomeSolid, Glyph=, Color={StaticResource Primary},Size=16}" />
</Grid>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
To add more information: I am okay with Internet load time which is <=1.5 seconds the time I calculate and show here is exclusively for When I set the ViewModel to Values from temporary variable to main variable I did it just to see if DB access is slow or not. (to step it out). I have my control inside a StackLayout that use Xamarin Community Toolkit statelayout.
Also I go through MS's Suggestion on optimizing performance about Compile XAML etc, but since it is new App using Xamarin Forms 5.0 I don't think it is problem as it is already set by default.

Windows Universal App (10) Hiding Bar

I'm creating universal application on windows 10, where I can create simple list.
And I have problem. I would like to create hiding top bar. When user swipe down, bar fade in to screen from top (something like status bar, when swipe it shows all content). Can you give my any tips where I should look for solution or gave me one? I use also GestureRecognizer but it does not work well with Scroll Viewer.
Here is my User Control with bar:
<Grid>
<Grid Margin="0">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Rectangle Fill="DarkOrange" Grid.Row="0" Margin="0"/>
<TextBox Name="TextBox" KeyDown="TextBox_KeyDown" Grid.Row="0" Margin="-2,5,2,13" Style="{StaticResource TextBoxStyle1}" Grid.RowSpan="2"/>
<Polygon Grid.Row="1" Points="0,0, 40,25, 0,50" Fill="DarkOrange" Margin="172.584,-30.584,186.416,-7.25" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto" >
<Polygon.RenderTransform>
<CompositeTransform Rotation="90"/>
</Polygon.RenderTransform>
</Polygon>
</Grid>
Here is page where I would like to use this bar:
<Grid Background="Black" Name="LayoutRoot" PointerPressed="OnPointerPressed" PointerReleased="OnPointerReleased" Margin="0,-76,0,0" >
<Grid.RowDefinitions>
<RowDefinition Height="49*"/>
<RowDefinition Height="309*"/>
</Grid.RowDefinitions>
<ScrollViewer Grid.Row="1" Name="scrollViewer" VerticalScrollMode="Enabled" ManipulationMode="All" ManipulationStarted="ScrollViewer_ManipulationStarted" DirectManipulationCompleted="ScrollViewer_DirectManipulationCompleted" DirectManipulationStarted="ScrollViewer_DirectManipulationStarted" IsEnabled="True" >
<StackPanel Name="sc" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollMode="Enabled">
</StackPanel>
</ScrollViewer>
</Grid>
Finally, I stared looking for pull to refresh. And I found this! pull to refresh Sample
Very nice samples :)

Image showing in the designer view in VS2013 but not displaying on the phone in wp8

I want to display an image inside the page of an app.. It is showing in the designer view of the VS2013 but when I run the app on the phone its not showing..
Following is the xaml :
<Grid x:Name="LayoutRoot" Background="#FFFFD9">
<Grid.RowDefinitions>
<RowDefinition Height="768"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel Grid.Row="0" Margin="0,10,12,623">
<TextBlock Text="" Style="{StaticResource PhoneTextNormalStyle}"/>
<Image HorizontalAlignment="Left" Height="118" Margin="10,0,0,0" VerticalAlignment="Top" Width="448" Source="images/brandlogo.jpg" RenderTransformOrigin="0.729,0.434" Stretch="Fill"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel Grid.Row="0" Margin="170,628,0,0">
<Image HorizontalAlignment="Left" Height="88" Margin="10,0,0,0" VerticalAlignment="Top" Width="100" Source="images/statusoffline.bmp" RenderTransformOrigin="0.729,0.434" Stretch="Fill"/>
</StackPanel>
</Grid>
Any help would be appreciated..
Make sure the Build action is set to Content on the properties of the image file in Visual Studio. That is generally recommended.

Slow Page loading when using ExpanderView & Binding (Windows Phone 7)

I have a Panorama control, which has an ExpanderView Item (from Silverlight toolkit).
My client wants this page to be customizable. Thats why I created 3 level of binding:
The PanoramaItems, the ExpanderView headers and the ExpanderView content.
The problem when I set the itemssource of the Panorama control. it takes about 5 seconds to show the items.
Any idea how I can solve this?
C# code:
private void panorama_Loaded(object sender, RoutedEventArgs e)
{
this.DataContext = App.Products;
}
XAML Code:
<controls:Panorama Loaded="panorama_Loaded" x:Name="panorama" ItemsSource="{Binding}">
<controls:Panorama.ItemTemplate>
<DataTemplate>
<ListBox ItemsSource="{Binding Sub_Products}" >
<ListBox.ItemTemplate>
<DataTemplate>
<toolkit:ExpanderView Header="{Binding}" Expander="{Binding}" ItemsSource="{Binding Sub_Sub_Products}">
<toolkit:ExpanderView.ExpanderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image VerticalAlignment="Center" Source="Images/List.png" Width="25" />
<TextBlock Text="{Binding Title}" />
</StackPanel>
</DataTemplate>
</toolkit:ExpanderView.ExpanderTemplate>
<toolkit:ExpanderView.ItemTemplate>
<DataTemplate>
<Grid Margin="-30,0,0,0" Background="White" Width="450" Tap="Grid_Tap" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Image Grid.Row="0" Source="{Binding ImageSource}" />
<StackPanel VerticalAlignment="Top" Grid.Column="1">
<TextBlock Text="{Binding Title}" />
<TextBlock Text="{Binding Description}" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
</Grid>
<TextBlock Margin="0,12,32,0" Grid.Row="1" Text="Learn more" />
</StackPanel>
</Grid>
</DataTemplate>
</toolkit:ExpanderView.ItemTemplate>
</toolkit:ExpanderView>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</controls:Panorama.ItemTemplate>
</controls:Panorama>
You could try to collapse the panorama items that are off screen and only set visibility to visible on demand. That should at least reduce the size of the visible tree.
A good way to find the slow parts is to use the profiler in Visual Studio. You will find one frame which is really slow (it will have a render time of 5 seconds in your case). Then dig into the visual tree of that frame and see which elements took a long time to render and try to optimize these.
Remove the ExpanderView ItemsSource binding in xaml and bind to it when the Expander is manupulated in code. Just leave it as ItemsSource="{Binding}". That way you will dynamically build you visual tree as the user taps on the expander.
The event handler is something like below. I am assuming Product is the type in your App.Products list. Also ensure that you hook up the event in your xaml for the expander.
private void ExpanderView_ManipulationStarted(object sender, System.Windows.Input.ManipulationStartedEventArgs e)
{
var expander = sender as ExpanderView;
expander.ItemsSource = (expander.DataContext as Product).Sub_Sub_Products;
}
Hope this solves your slow loading issues and is not too late at this time.

memory leak in window phone 7

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?

Resources