I have a following problem:
I want to load a next screen. And while next screen is loading I want to show loading animation to user.
Its could not be done on another thread than GUI thread.
And I need to run animation at the same time. Also in a gui thread..
The window with animation looks like this :
<Window
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:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
x:Name="Window"
Title="Loading"
Width="640" Height="480" Background="{x:Null}" WindowStyle="None" AllowsTransparency="True" VerticalAlignment="Bottom" WindowStartupLocation="CenterScreen" WindowState="Maximized">
<Grid x:Name="LayoutRoot" Background="#4C000000">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Width="277" Height="277">
<MediaElement x:Name="Loading" MediaEnded="Loading_MediaEnded" UnloadedBehavior="Manual"
Source="Images/Loading.gif" LoadedBehavior="Play" Stretch="None" Clip="M0.5,19.5 C0.5,9.0065898 9.0065898,0.5 19.5,0.5 L257.5,0.5 C267.99341,0.5 276.5,9.0065898 276.5,19.5 L276.5,257.5 C276.5,267.99341 267.99341,276.5 257.5,276.5 L19.5,276.5 C9.0065898,276.5 0.5,267.99341 0.5,257.5 z"/>
</Grid>
</Grid>
I create an instance of this class and call Show fuction
LoadingAnim loadingAnimation = new LoadingAnim();
loadingAnimation.Owner = this;
loadingAnimation.Show();
and after that I want to start loading the next screen.
The problem is that animation shows up only after 6 the screen loaded
I think that The problem is I run both of them on the gui thread.
Anyone have an idea what should I do in this case ?
Related
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Height="833.831" Width="1351">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Unloaded="Unlaoded" Margin="-47,0,0,0" HorizontalAlignment="Right" Width="1398">
<WebView x:Name="WebView" LoadCompleted="WebView_LoadCompleted" Height="814" VerticalAlignment="Top" Margin="-55,10,10,0" Grid.RowSpan="2" HorizontalAlignment="Right" Width="1396" RenderTransformOrigin="0.506,0.695"
/>
<ProgressRing x:Name="ProgressRing1"
Margin="642.019,405,671.173,378.647"
Height="50.353" Width="84.808"
Foreground="BlueViolet"
UseLayoutRounding="False" d:LayoutRounding="Auto"
>
<ProgressRing.RenderTransform>
<CompositeTransform Rotation="1.006"/>
</ProgressRing.RenderTransform>
</ProgressRing>
</Grid>
</Page>
hello all i am new to this forum and also i am new in uwp programming. I am in a desperate position and i need some help. I can't make the above webview responsive in all platforms(desktop,windows phone). I load webview from the code from local app and i can't make it adaptive in all platforms. Can anyone help me make it work from xaml.
Did i need to put
<RelativePanel .../>
in xaml code.
You should not use fixed values for Width and Height. Take a look at the following links:
Arranging UI Elements and
Layout with Absolute and Dynamic Positioning
to have an idea of how positioning works in XAML.
I think you created the UI using the designer, that's why you got those values.
Following is a simple example where the web view is filling all the space from the page:
XAML
<Page
x:Class="Stack1.MainPage"
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"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<WebView
x:Name="WebView"
LoadCompleted="WebView_LoadCompleted"
Source="https://www.google.com"/>
<ProgressRing x:Name="ProgressRing"
Foreground="BlueViolet"
IsActive="True"
Width="100"
Height="100"
>
</ProgressRing>
</Grid>
C# code behind
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void WebView_LoadCompleted(object sender, NavigationEventArgs e)
{
ProgressRing.Visibility = Visibility.Collapsed;
}
}
The ProgressRing will be visible until the web-view content will be loaded (use of LoadCompleted event)
Related to Adaptive UI you can take a look at this video.
If your embedded website URL source is responsive, below code changes will help to you fit your website for all screen sizes. Auto layout size and alignment will help you to fit all screen sizes.
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Unloaded="Unlaoded">
<WebView x:Name="WebView" LoadCompleted="WebView_LoadCompleted" />
<ProgressRing x:Name="ProgressRing1"
Height="50.353" Width="84.808"
Foreground="BlueViolet"
UseLayoutRounding="False" d:LayoutRounding="Auto" />
</Grid>
</Page>
When I try adding more than one element to my WPF form in the editor in VC#2013, the previous element disappears. In the end, I can't have more than one item in the form. I've already written some code so I'd prefer not starting again from scratch. The form has nothing special besides being borderless, fullscreen and starting maximized.
This is the XAML code for the form right now:
<Window x:Class="queue_bigscreen.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="1080" Width="1920" WindowStyle="None" ResizeMode="NoResize" WindowState="Maximized" Background="#FF9EA7CD">
<Label x:Name="nowServingLabel" Content="0" Margin="42,56,1160,131" Foreground="White" Height="893" FontSize="700" HorizontalContentAlignment="Center">
<Label.Effect>
<DropShadowEffect ShadowDepth="13"/>
</Label.Effect>
</Label>
</Window>
And this is what I get after I select a textbox and try adding it to the form:
<Window x:Class="queue_bigscreen.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="1080" Width="1920" WindowStyle="None" ResizeMode="NoResize" WindowState="Maximized" Background="#FF9EA7CD">
<TextBlock HorizontalAlignment="Left" Margin="1332,382,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/>
As you can see, the label disappears, and the textbox I added in turn disappears if I try adding something else. Am I doing something wrong or is it a known bug?
You need to put the items in a container. Window can only have a single root element, so to get multiple elements on the form, you need to have an element that allows children.
The closest to Windows Forms Form would be Grid. You can then put controls in that, with absolute and relative positioning. It's also the default, so I assume you accidentally deleted it from your XAML (or by being too aggressive with pressing delete in the designer).
Example form with a label and a textbox:
<Window x:Class="WpfApplication1.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>
<Label Content="Label" HorizontalAlignment="Left" Margin="23,30,0,0" VerticalAlignment="Top"/>
<TextBox HorizontalAlignment="Left" Height="23" Margin="66,32,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
</Grid>
</Window>
I have a usercontrol that I am placing in a grid. Inside the grid I am also drawing lines. These lines appear above the usercontrol like they should.
When the user clicks on my usercontrol, I am showing another part of the usercontrol, an xaml element (making it visible) and I need it to appear above the drawn lines.
I've tried Canvas.ZIndex. That seems to only work with elements inside my usercontrol. If I set the usercontrols ZIndex high, then it all appears above the lines.
Here is the Min working example:
I need the Blue square to stay below the black line and the yellow ellipse to be above the black line.
--Main Page--
<UserControl xmlns:SWE_UserControlOverlap="clr-namespace:SWE_UserControlOverlap" x:Class="SWE_UserControlOverlap.MainPage"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<SWE_UserControlOverlap:SWE />
<Line Stroke="Black" StrokeThickness="10" Stretch="Fill" X1="0" Y1="0" X2="1" Y2="1"></Line>
</Grid>
</UserControl>
--UserControl--
<UserControl x:Class="SWE_UserControlOverlap.SWE"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<Rectangle Fill="Blue" MouseLeftButtonUp="Rectangle_MouseLeftButtonUp_1"></Rectangle>
<Ellipse Margin="100" Fill="Yellow" ></Ellipse>
</Grid>
</UserControl>
Don't set a ZIndex on the control, just modify it for the sub controls.
<Line Canvas.ZIndex="1" />
<Rectangle Canvas.ZIndex="0" />
<Ellipse Canvas.ZIndex="2" />
As I found in various spots on the web - this is just not possible.
I am having a C# WPF application that runs in full screen. When I place a button in the top right of the canvas and run the application the button doesn't appear. What i figured it out is that the canvas is larger than the screen although I made it the same width and height as the screen resolutions.
PS: The application is working fine on another computer and the canvas size is correct but when I run it on my laptop or PC the same problem appears.
<Window x:Name="Mywindow" x:Class="Graduation_Project.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" SizeToContent="WidthAndHeight" Height="768" Width="1366" WindowStyle="None"
ResizeMode="NoResize" WindowStartupLocation="CenterScreen"
WindowState="Maximized" Topmost="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Canvas Name="workspace">
<Label x:Name="Print" Content="Label" Canvas.Left="57" Canvas.Top="719" Width="74"/>
</Canvas>
</Window>
Remove the Height="768" and Width="1366" properties from the Window.
SOLUTION here
I was asked to emulate a windows forms context menu using a WPF window. I created a window when the user clicked a certain region, but that window got minimized to the task bar instantly. I need it to stay on top of other windows at least until it loses focus or is deactivated. Its window style is none, and it doesn't matter whether its show in taskbar property is true or false. Similar questions exist on SO, but they don't seem to solve anything in my case. Why this odd behavior? Is there a fix for it?
<Window x:Class="InterceptRouteWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Width="200" ResizeMode="NoResize" SizeToContent="Height" ShowInTaskbar="False" Loaded="Window_Loaded" WindowStyle="None" Height="auto" Deactivated="Window_Deactivated">
<StackPanel Height="auto" Name="stackPanel1" Width="200" Background="WhiteSmoke">
<Separator Height="5" FlowDirection="LeftToRight">
<Separator.Background>
<SolidColorBrush />
</Separator.Background>
</Separator>
</StackPanel>
</Window>
So it's a simple window. The way I invoke it:
IRWindow = gcnew InterceptRouteWindow(routes, fpId, offsetPoint.x, offsetPoint.y);
GetMainFrame()->IRWindow->Show();
This is triggered by a click event inside an older app, a mixture of MFC and WindowsForms.. not my code, I had to obey their design and use WPF where I could.