Visual Studio stuck on fullscreen UWP app error - visual-studio

When debugging a fullscreen Win2d UWP app from VS and my code has an error, the app window gets frozen "always-on-top" style, forcing me to reboot or log out of windows. The app was still showing the blue startup image with no top bar access.
I tried Alt+F4, Shift+Win+Enter, Alt+Tab. The app stays fullscreen and on top even after closing it. The Win key reveals the taskbar but closing VS fails because it creates an unreachable confirmation dialog about stopping the debugger. Task manager is also unusable, hidden behind the frozen app. I've removed this line for now, but I want to start in fullscreen always.
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
Here's example code using the Win2d quick start guide that causes the problem for me:
MainPage.xaml
<Page
x:Class="Example.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Example"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:canvas="using:Microsoft.Graphics.Canvas.UI.Xaml"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<canvas:CanvasControl x:Name="canvas" Draw="canvas_Draw"/>
</Grid>
</Page>
MainPage.xaml.cs
using Microsoft.Graphics.Canvas.UI.Xaml;
using System;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml.Controls;
namespace Example
{
public sealed partial class MainPage : Page
{
public MainPage()
{
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
this.InitializeComponent();
}
private void canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args)
{
throw new Exception("error in my code");
}
}
}

Related

How to Open multiple window using AppWindow in xamarin forms UWP?

As i have using 'AppWindow' to open separate window in xamarin forms UWP. I tried below code to open the window,
if (appWindow == null)
{
appWindow = await AppWindow.TryCreateAsync();
Frame appWindowFrame = new Frame();
appWindowFrame.Navigate(typeof(testpage));
ElementCompositionPreview.SetAppWindowContent(appWindow, appWindowFrame);
}
await appWindow.TryShowAsync();
When 'Appwindow.TryCreateAsync' method calling, it will be thrown 'Class not registered exception'. Please see the below snippet,
I tried to check about this issue and also trying to find a solution. But i am not getting any solution to fix this. Please let me know, if you have faced same this issue or any solution to fix it.
Please make sure your testpage extend Page.
I create a blank page called AppWindowMainPage like following screenshot.
AppWindowMainPage.cs
public sealed partial class AppWindowMainPage : Page
{
public AppWindowMainPage()
{
this.InitializeComponent();
}
}
AppWindowMainPage.xaml
<Page
x:Class="App75.UWP.AppWindowMainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App75.UWP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<TextBlock Text="test"></TextBlock>
</Grid>
</Page>
When I run the code, it could open a new window.

Xamarin Form Animation

I have a simple code that uses ScaleTo method to build a simple animation and the code was working fine up to last Friday and all of the sudden it's not working any more.
Here is my XAML file:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="TestAnim.MainPage">
<StackLayout Orientation="Vertical">
<Image Source="discount.png" x:Name="img" Scale="0.1"/>
<Button Text="Do" Clicked="doIt"/>
</StackLayout>
</ContentPage>
And here is my C# code:
using System;
using System.ComponentModel;
using Xamarin.Forms;
namespace TestAnim
{
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
async void doIt (object sender , EventArgs ev)
{
await img.ScaleTo(1, 2000, Easing.BounceOut);
await img.ScaleTo(0.1, 3000, Easing.BounceIn);
}
}
}
When I run the code, I see no effects at all, if I comment the 2nd ScaleTo call I see my image scales to 1 but this happens immediately instead of within 2 seconds! As result when I have the 2nd scale really the end result is no see no animation at all.
This was working fine before as I mentioned but for some reason the duration seems to be ignored and the scaling seems to happen instantly which is the issue here.
Any one else see the same problem?
If you are using Xamarin.Forms version 4.2+ there is currently a bug about Animations, you can track it here.
I've reproduced your code in Xamarin.Forms 4.1.0.581479 and it is working just fine.

After Creating Package in Xamarin UWP, Video is Playing Only With Voice, I am Not able to see Video

I am using MediaManager Plugin with latest version to play a video. everything works fine when i run application in debug mode, but when i create a package for window, video is not showing only voice is heard.
I am using below Package
Plugin.MediaManager.Forms
This is My XAML page
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Digi_Sign.Views.MediaScreen"
xmlns:forms="clr-namespace:MediaManager.Forms;assembly=MediaManager.Forms"
BackgroundColor="Black">
<ContentPage.Content>
<Grid x:Name="stkLayout" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" BackgroundColor="Black">
<forms:VideoView VideoAspect="AspectFill" x:Name="videoPlayer" ShowControls="False" />
</Grid>
</ContentPage.Content>
</ContentPage>
CS Page
CrossMediaManager.Current.Play(fileName);
No Errors Found in package error log, as i mentioned everything works fine when it is debug mode, but not working in release mode
Basically there is no way to initialize renderer for video in native code for xamrin.UWP, so we need to manually load render assembly in initialize it in App.xaml.cs of UWP platform
Below is my code where i have load assembly files inside OnLaunched() and replace existing Xamarin.Forms.Forms.Init()
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
Windows.UI.Xaml.Controls.Frame rootFrame = Window.Current.Content as Windows.UI.Xaml.Controls.Frame;
if (rootFrame == null)
{
rootFrame = new Windows.UI.Xaml.Controls.Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
List<Assembly> assembliesToAdd = new List<Assembly>();
assembliesToAdd.Add(typeof(VideoViewRenderer).GetTypeInfo().Assembly);
Xamarin.Forms.Forms.Init(e, assembliesToAdd);
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
Window.Current.Activate();
}
for more details, here is the link. where you can find more explaination.
https://forums.xamarin.com/discussion/119451/crossmedia-works-in-debug-but-not-in-release-for-uwp-error-msg-about-onecore
Most likely from the behavior you are describing (and looking at your code), it sounds like it's because the Video is not being run on the UI thread, and this causes the app to play the audio but not the video. So change it to the following:
Device.BeginInvokeOnMainThread(() => { CrossMediaManager.Current.Play(fileName); });

How to preview an ItemTemplate in the XAML designer

Say I have a simple ItemTemplate for a ListView
<ListView ItemsSource="{x:Bind ListItems}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="local:TextItem">
<TextBlock Text="{x:Bind Item}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
MainPage.xaml
When I run the app, I get a ListView populated with TextBlocks - one for each item in ListItems (which is a behind defined variable). However, in the XAML designer, I see nothing.
So, is there a way to preview the ItemTemplate/DataTemplate in the XAML designer, with a set number of placeholder TextBlocks with placeholder text replacing the Text="{x:Bind Item}"? Or just preview a single TextBlock?
This is not a duplicate of
Design View of a DataTemplate in a ResourceDictionary in Visual Studio - because I can't use Blend. Everything I've looked up that says use Blend in a certain way merely gives me the message 'This feature is not available for projects targeting "Windows 10 Fall Creators Update (10.0; Build 16299)"'
Can I preview my DataTemplate(s) in my collection-based controls in the designer? - well, perhaps it is, but I don't understand the accepted answer, which is now several years old. An answer containing an example tailored to my question would be really helpful.
Microsoft actually posted a (semi helpful) tutorial on this in April of this year: link
Requirements
Whatever you want to display, you will need this at the top of your XAML code (should be there by default if you created the page using VS's templates):
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
A simple list of strings
For something simple like a list of strings, something like this will work just fine (taken from the above mentioned MSDN page):
<ListView>
<d:ListView.Items>
<system:String>Item One</system:String>
<system:String>Item Two</system:String>
<system:String>Item Three</system:String>
</d:ListView.Items>
</ListView>
Display something more complex
If you want to use a data source from somewhere else in your code, it gets a little more ugly:
First you need to set your data context (usually done at the page level, but you can also add it just on the element where you want to use it):
d:DataContext="{d:DesignInstance
yournamespace:YourDataSourceClass,
IsDesignTimeCreatable=True}"
And on the ListView add:
d:ItemsSource="{Binding data}"
If you are using an ItemTemplate, you will need to add "d:" variants for everything you want to pull from your data source.
Full example code:
XAML:
<Page
x:Class="exampleApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:exampleApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance local:DesignTimeData,
IsDesignTimeCreatable=True}"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Grid>
<ListView ItemsSource="{x:Bind ListItems}" d:ItemsSource="{Binding DummyData}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="local:TextItem">
<TextBlock Text="{x:Bind Item}" d:Text="{Binding Item}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Grid>
</Page>
C#:
using System.Collections.ObjectModel;
using Windows.UI.Xaml.Controls;
namespace exampleApp {
public sealed partial class MainPage : Page {
public ObservableCollection<TextItem> ListItems;
public MainPage() {
this.InitializeComponent();
//populate you ListItems list
}
}
public class TextItem {
public string Item { get; set; }
}
public class DesignTimeData {
public ObservableCollection<TextItem> DummyData { get; set; } = new ObservableCollection<TextItem> {
new TextItem { Item = "foo" },
new TextItem { Item = "bar" },
new TextItem { Item = "bla" },
new TextItem { Item = "blubb" }
};
}
}
Remarks
It seems you have to use "Binding" rather than "x:Bind" for the design-time bindings. From what I understand, x:Bind works using code generated at compile time, which is not executed by the XAML designer
When you change your Binding declarations or data source code, you will have to recompile to see the changes in the designer. Other design changes will reflect in real time
Binding is more limited than x:Bind in some regards (notably you cannot bind to class methods using Binding, only x:Bind). Keep that in mind when writing your design-time data
Sadly some of the more convenient ways of getting design-time data into your app are WPF and Xamarin only (Blends' data window, data declared in XAML file, and especially auto-generated sample data)
(Everything was tested using Visual Studio 2019 version 16.10.3.)

Burn-in test for WP7

I'm experiencing very strange issues while developing a WP7 app that happen usually after 30m or 1h, despite the code is really simple, almost equal to examples. The emulator does not have any problem.
app crashes with no exception being thrown
unhandled exception: {"0xffffffff"} (Yes, message is "0xffffffff". And Stacktrace is null)
once i got an exception thrown while getting DateTimeOffset.Now property (!)
UI Thread frozen, couldn't terminate app, had to power cycle the device
So at this point i think that either WP7 is really unstable or my device hardware is faulty.
Does a burn-in test exists for WP7? Like Memtest86, Prime and other utilities for the desktop?
Edit: here is the code that is causing problems:
public partial class MainPage : PhoneApplicationPage
{
private Accelerometer _accelerometer;
private GeoCoordinateWatcher _gps;
public MainPage()
{
InitializeComponent();
_accelerometer = new Accelerometer();
_accelerometer.ReadingChanged += new EventHandler<AccelerometerReadingEventArgs>(_accelerometer_ReadingChanged);
_accelerometer.Start();
_gps = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
_gps.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(_gps_PositionChanged);
_gps.Start();
}
void _gps_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
Dispatcher.BeginInvoke(() =>
{
TBLocation.Text = e.Position.Location.ToString();
});
}
void _accelerometer_ReadingChanged(object sender, AccelerometerReadingEventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
TBAccelX.Text = string.Format("X: {0:F2} g", e.X);
TBAccelY.Text = string.Format("Y: {0:F2} g", e.Y);
});
}
}
<phone:PhoneApplicationPage
x:Class="AccelerometerTest2.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"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<StackPanel>
<TextBlock Name="TBAccelX"/>
<TextBlock Name="TBAccelY"/>
<TextBlock Name="TBLocation"/>
</StackPanel>
</phone:PhoneApplicationPage>
EDIT: As i suspected the phone was faulty. The app had run properly on another device for 5 hours.
I would suspect a memory (or resource) leak.
What does the app do?
Does the error happen while using the app or if you just leave it?
Is the app doing anything on a timer?
Have you tried monitoring memory usage over the lifetime of the app?
As there are fewer other apps and things going on in the background with the emulator, the need for the system to reclaim resources from you app is likley to be much less. It is therefore possible that such issues may not also be seen on the emulator.
If you get the latest (beta) version of the [mango] developer tools you'll be able to run your code through the new, built in profiler so you can see what is happening over time.

Resources