I've this ad control in each of my app's pages
<UI:AdControl
ApplicationId="my app id"
AdUnitId="my unit id"
Height="50"
Width="320"
ErrorOccurred="AdControl_ErrorOccurred"
IsAutoRefreshEnabled="True"
VerticalAlignment="Bottom"
HorizontalAlignment="Center"/>
After a few navigation back and forth it causes a memory leak and app crashes. as simple as that.
What can I do to avoid this? is there a way to have one instance of this control globally and use it in each page?
Thanks.
Related
I have a user control LoadingIndicatorControl which is displayed in various other controls when loading is happened.
This user control is very simple and looks like this:
<StackPanel HorizontalAlignment="Stretch"
Visibility="{Binding Loading, Converter={StaticResource Bool2Vis}}">
<Image x:Name="imgLoadingSpinner"
gif:ImageBehavior.AnimatedSource="pack://application:,,,/Images/Loading_Spinner.gif"
HorizontalAlignment="Right"
Width="30"
Height="30" />
</StackPanel>
I nest it in other views like this:
<uc:LoadingIndicatorControl Loading="{Binding Loading}"
DockPanel.Dock="Bottom"/>
When I run this application it compiles without issues and the loading indicator is displayed as I expect.
However at design time only I'm getting errors about this user control, related to the image resource. This gif is set to Build Action Resource.
In my host view I get this:
And if I look at the detail of why, it says Cannot locate resource 'images/loading_spinner.gif':
If I look at LoadingIndicatorControl in design view it does in fact locate the loading_spinner.gif resource and gives no errors.
What I have tried:
Clean and rebuild numerous times
Close VS2019 and reopen
Clean, close VS, reopen and rebuild
Set Loading_Spinner.gif Build Action to Embedded Resource (was Resource which also works at runtime)
Tried platform targets Any CPU, x64, x86
Interestingly, setting to build configuration to Release does prevent the error from appearing! It only appears when Debug is used.
I'm using Visual Studio Professional v16.11.16.
Any ideas how I can fix this?
Just use the direct path to the image:
<Image gif:ImageBehavior.AnimatedSource="Images/Loading_Spinner.gif"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Width="30"
Height="30" />
If you really need the pack URI, the format is explained here, it look like this:
<Image gif:ImageBehavior.AnimatedSource="pack://application:,,,/SO_72648958;component/Images/Loading_Spinner.gif"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Width="30"
Height="30" />
Working demo here.
I'm working on a WPF application and am trying to embed a twitch/youtube/facebook gaming stream. I am relatively new to WPF applications in general.
I've followed the steps outlined at the Twitch Embed API Page, and attempted to insert it into a CEFSharp window using the Twitch embed code. However, as of 2020, twitch now requires a "parent" field to embed their videos, so I just tried plugging the actual twitch page into the CEFsharp element and still it gave me an error.
For Facebook and Youtube, I could get the embedded frames to show up as well, but they both failed to load the video, which leads me to believe there is an issue displaying streaming media through CEFSharp?
Here is the code :
...
xmlns:cef="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
...
<cef:ChromiumWebBrowser
Width="480"
Height="270"
HorizontalAlignment="Left"
Margin="0,20,0,0"
Address="https://www.twitch.tv/shroud"
/>
<cef:ChromiumWebBrowser
Width="480"
Height="270"
HorizontalAlignment="Left"
Margin="0,20,0,0"
Address="https://www.youtube.com/embed/Xz5Nw0EY5ng"
/>
<cef:ChromiumWebBrowser
Width="480"
Height="270"
HorizontalAlignment="Left"
Margin="0,20,0,0"
Address="https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2FNitroLukeDX%2Fvideos%2F710121262901568%2F&show_text=0&width=560" />
And here's the result:
Any help would be greatly appreciated!
Ahaa in the end someone pointed me towards the new WebView2 control from ms.
This plays streaming video :D
<wv2:WebView2 Name="webView"
HorizontalAlignment="Left"
Height="270"
Width="480"
Margin="0,20,0,0"
Source="https://player.twitch.tv/channel=loltyler1"/>
I'm new in creating apps for Windows Phone. I've got problem with redirecting to another page. I've created blank page with HyperlinkButtonand in .cs file I wrote this:
private void but_elf_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(Elfy));
}
In xaml:
<HyperlinkButton x:Name="but_elf" Content="Elfy"
HorizontalAlignment="Center" Margin="100,125,100,255" Grid.Row="1"
VerticalAlignment="Center" Width="200" Height="70" />
When I launch app and click on the button - nothing happens. There are no errors, no messages. I've tried to put NavigateUri in button's property but after pressing button (in launched app) the message has shown: "You need to install an app for this task. Would you like to search for one in the Store?" After pressing "Yes" the app says: "Sorry, no apps found".
How to figure out this problem? I'm creating app for Windows Phone 8.1 in .NET Framework 4.5. Thanks for any help.
You are missing a reference for the 'Click'-event handler. Please change your XAML to this:
<HyperlinkButton x:Name="but_elf" Content="Elfy"
HorizontalAlignment="Center" Margin="100,125,100,255" Grid.Row="1"
VerticalAlignment="Center" Width="200" Height="70" Click="but_elf_Click" />
Please see:
C# Documentation for Click on MSDN
C# Documentation for HyperlinkButton on MSDN
I am creating Windows Phone 8 silverlight application and i am using map control with toolkit MapExtensions to bind the pins on the map. But when I navigate away from map screen or come back to this screen it takes normally 2 to 3 sec to load this page. Where as when application is navigating between other non map pages it is fast. How can i improve application performance regarding map load and unload time while navigation. Here is the map control code I am using:
<maps:Map x:Name="map"
Center="{Binding CenterLocation,
Mode=TwoWay}"
CacheMode="BitmapCache"
ColorMode="Light"
Background="White"
>
<i:Interaction.Triggers>
<i:EventTrigger EventName="ResolveCompleted">
<i:InvokeCommandAction Command="{Binding MapResolveCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<tool:MapExtensions.Children>
<tool:UserLocationMarker GeoCoordinate="{Binding CurrentLocation,Mode=TwoWay}"
Width="50"
Height="50"
Style="{StaticResource LocationMapMarker}">
</tool:UserLocationMarker>
<tool:MapItemsControl Name="mapItems">
<tool:MapItemsControl.ItemTemplate>
<DataTemplate>
<tool:MapChildControl GeoCoordinate="{Binding ItemLocation, Converter={StaticResource LocationToGeoCoordinateConverter}}">
<tool:MapChildControl.Content>
<Image
Source="{Binding ItemId,
Converter={StaticResource ImageConverter}}" />
</tool:MapChildControl.Content>
</tool:MapChildControl>
</DataTemplate>
</tool:MapItemsControl.ItemTemplate>
</tool:MapItemsControl>
</tool:MapExtensions.Children>
</maps:Map>
This is to be expected. The map control is a pretty heavy control as there is a lot of moving parts to it. In addition to that, by putting it on a page, every time you move to the page the Map is recreated. What you can do is create a single map and reuse it across all the pages. I wrote a blog post on how to do this for Windows Store apps here: https://rbrundritt.wordpress.com/2014/10/24/be-smooth-optimize-bing-maps-in-multipage-windows-store-apps-javascript/
This was for a JavaScript application so this only shows the concept and would take a decent amount of work to port over.
So I was have a combobox like below, coded like this;
AllowsTransparency="True" Background="Transparent">
<Border CornerRadius="10" Background="Beige" BorderBrush="Aqua" BorderThickness="2">
<Grid>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<Label Name="lblText"></Label>
<ComboBox Name="cbxNumbers"></ComboBox>
<TextBox Name="txtNumbers" Visibility="Collapsed"></TextBox>
<Button HorizontalAlignment="Center" Name="btnDone"
Click="btnDone_Click">That's Right!</Button>
</StackPanel>
<Button VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="1"
FontSize="8" Name="btnChangeInput" Click="btnChangeInput_Click">Let me chose the number
</Button>
</Grid>
</Border>
And then populated in code like this;
lblText.Content = Text;
cbxNumbers.Items.Add(5);
cbxNumbers.Items.Add(10);
cbxNumbers.Items.Add(50);
cbxNumbers.Items.Add(100);
cbxNumbers.Items.Add(1000);
cbxNumbers.Items.Add(10000);
cbxNumbers.Items.Add(100000);
cbxNumbers.Items.Add(1000000);
cbxNumbers.SelectedIndex = 0;
My question is obviously, why is my Dropdown showing beneath my window?
UPDATE
Quote Microsoft
Thank you for reporting this issue. Though this issue is under
investigation, we will likely not have a fix available in .NET 4.0. We
will update this bug again when we are able to fix the issue in a
future release. Thanks!
Great... any ideas for a work around?
This is a well documented bug with AllowTransparency=TRUE. It only happens on some computers running Win XP.
http://connect.microsoft.com/VisualStudio/feedback/details/465964/wpf-combobox-dropdown-list-appears-behind-the-form-when-allowstransparency-true
A workaround is found here:
As noted before, this is an issue with layered windows on XP. There is
not much that can be done at the WPF level to solve this, and given
that XP is no longer being serviced this isn't very likely to be
fixed. There are potentially workarounds you can employ, though.
The source of the problem is that WPF uses something called "Layered
Windows" when WindowStyle=None and AllowsTransparency=True. Often the
reason for doing this is to implement custom window chrome. Recently
the WPF team published a library that allows you to get custom chrome
without resorting to layered windows. The library is available at
http://code.msdn.microsoft.com/WPFShell
This doesn't support per-pixel opacity, but it does allow for
completely custom rendering of the window, including areas normally
managed by the system. It lets you set the radii of the windows
corners, but not have a completely arbitrary shape. If you can use
this library instead of AllowsTransparency=True then it should solve
this issue.
Microsoft has issued a hotfix, but it seems to not have fixed all problems related to the issue.