Removing the broadcasting icon when player is in fullscreen on MediaElement - xaml

I am using the default MediaElement with AreTransportControlsEnabled="True" and I am trying to remove the CastButton element when the app is in full screen.
I have already created a copy of MediaTransportControls and commented out the CastButton but this doesn't work when in fullscreen any ideas?
Here is the sample project attached:
https://www.dropbox.com/s/83wt4adr8db7xqu/App1.zip?dl=0
My code :
<Style TargetType="MediaTransportControls">
bla bla
<ControlTemplate TargetType="MediaTransportControls">
bla
<!--<AppBarButton x:Name='CastButton'
Style='{StaticResource AppBarButtonStyle}'
Visibility="Collapsed"
MediaTransportControlsHelper.DropoutOrder='7'>
<AppBarButton.Icon>
<FontIcon Glyph=""/>
</AppBarButton>-->
bla
bla
My MediaElement:
<MediaElement Source="http://smf.blob.core.windows.net/samples/videos/bigbuck.mp4"
AreTransportControlsEnabled="True"
></MediaElement>

You're almost done correctly. The main reason that your xaml wasn't merged in global dictionary your application. Just move you xaml code:
To App.xaml
Or create some file, which will be contains you style and merge this xaml style with resource dictionary in App.xaml
You can see it by code bellow:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Styles/MediaElementStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
I did it through second way. Your project link

Related

Implementing TeachingTip control for a UWP App

To install the TeachingTip-control in my UWP app, I've done the following stepts:
installed Microsoft.UI.Xaml package via Nuget in my project
Added <XamlControlsResources xmlns = "using:Microsoft.UI.Xaml.Controls" /> into App.xaml.
Imported Namespace xmlns:controls="using:Microsoft.UI.Xaml.Controls"
I implemented the TeachingTip-control as follows:
<Button x:Name="BackButton"
Background="{x:Null}"
Content="Back"
Click="BackButton_Click">
<Button.Resources>
<controls:TeachingTip x:Name="ToggleThemeTeachingTip"
Target="{x:Bind BackButton}"
Title="Change themes without hassle"
Subtitle="It's easier than ever to see control samples in both light and dark theme!"
CloseButtonContent="Got it!">
</controls:TeachingTip>
</Button.Resources>
</Button>
<Button x:Name="TeachingTipButton"
Click="TeachingTipButton_OnClick">
</Button>
private void TeachingTipButton_OnClick(object sender, RoutedEventArgs e)
{
ToggleThemeTeachingTip.IsOpen = true;
}
When I call the function I get the following DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION error (probably UI error), which I do not understand:
What could be the problem? Why does not my code work?
Edit:
I have now determined that the error is due to App.xaml. After I've installed the Nuget package Microsoft.UI.Xaml, it's expected to add the following code in App.xaml:
But I have already in App.xaml other settings and resources:
When I try to add only the line in App.xaml a key error occurs:
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
If I give the resource entry a key like this:
<XamlControlsResources x: Key = "XamlControlsResources" xmlns = "using: Microsoft.UI.Xaml.Controls" />
 It comes to a completely different error:
Windows.UI.Xaml.Markup.XamlParseException: "The text for this error is not found.
Can not find a Resource with the Name / Key TeachingTipBackgroundBrush
How can I properly add the resource <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/> correctly in my App.xaml?
Your App.xaml file needs to look like this:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
</ResourceDictionary.MergedDictionaries>
<!-- Other styles here -->
<Style TargetType="Button">
...
</Style>
</ResourceDictionary>
</Application.Resources>
I pasted your code into my project and it worked. However, the code you provided above doesn't have Content for the triggering button, so the only button which appears is the top button. Are you sure you're not failing because of code in BackButton_Click rather than TeachingTipButton_OnClick?
You can remove the duplicate reference to Microsoft.UI.Xaml.Controls from Application.Resources
I solved my problem by removing ContentDialog Size style and Default Button style so that <Application.Resources> has only <XamlControlsResources x: Key = "XamlControlsResources" xmlns = "using: Microsoft.UI.Xaml.Controls" /> as a single entry. In my case, multiple entries in <Application.Resources> </Application.Resources> are unfortunately not accepted.

UWP The attachable property 'Resources' was not found in type 'Style'

In ResourceDictionary file I have a style and I try to add few resources to that style. Unfortunately, the member Resources is not recognized or is not accessible. I need keep resources explicitly within a style.
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestProject.Resources">
<Style>
<Style.Resources> <!--Style doesn't like it here-->
Uwp's style seems to doesn't like it. Is there any equivalent or sufficient workaround? Or I am doing something completely wrong.
Style does not have Resources property (see documentation). Controls and visual elements do. If you want to add resources, you can add them either under a control, all on the same level as the Style element:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestProject.Resources">
<SolidColorBrush x:Key="MyBrush" ... />
<Style>
<!-- use MyBrush in this style -->
If you define resources on the same level as the Style they will be unfortunately available globally, but that is similar how the default UWP styles are defined in the default XAML resource dictionaries (generic.xaml).

Navigating second time causes "cycle detected in merged resource dictionaries" exception

I am experiencing a very weird problem using Merge Dictionaries in my windows phone app. I navigate to secondary page (page1) from my MainPage, with a very simple button click
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
}
First time navigating goes correct. A second time (back and click button again) gives me an error "cycle detected in merged resource dictionaries". I created a very simple page and can reduce the problem just by adding the MergedDictionary + resourcedictionary. My Page1.xaml is the following:
<phone:PhoneApplicationPage.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Skins\Page1Skin.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</phone:PhoneApplicationPage.Resources>
Sorry for necroposting, but this topic is only one in whole web search which talking about this issue on WP8.0 (Silverlight).
Solution above didn't help me, so I found another one:
<phone:PhoneApplicationPage.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MyProject.WP;component/Styles/MyPageStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</phone:PhoneApplicationPage.Resources>
Where:
"MyProject.WP" - my main project. This is name of it in a Solution.
"Styles" - folder in the solution.
";component" - keyword for referencing on Assemblies.
In this case also you can select styles from another projects, just need to change Project Name in Source.
Found it. I have a tiny mistake in my XAML. The backslash in the path to the ResourceDictionary must be a forward slash.
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Skins\Page1Skin.xaml"/>
</ResourceDictionary.MergedDictionaries>
Replacing it solved my problem. No clue why phone fails with this error!

How to localize page title using resource files (.resw)?

I need to translate the title of basic page in windows8 app. Here is a xaml string:
<Page.Resources>
<!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
<x:String x:Uid="title_select_profile" x:Key="AppName">Select profile</x:String>
</Page.Resources>
So, the trick with Uid doesn't work here. How to get accsess to this string from resource file?

Are you not able to have resources in App.xaml if you merge in resource dictionaries?

We have 4 global resources attached in app xaml that are classes we use in our application to maintain state for various items.
Here is how we have them in app.xaml
<Application.Resources>
<AMSI:Global x:Key="AMSI.Global"/>
<eFin:Global x:Key="eFinancials.Global" />
<eService:Global x:Key="eService.Global" />
<eSite:Global x:Key="eSite.Global" />
... a bunch of styles and control templates here...
</Application.Resources>
After reading chapter 23 I decided I was going to clean some stuff up and create few resource dictionaries.
So, I used blend and created two resource dictionaries and moved all the styles to them. Blend modifyied my xaml to the following:
<Application.Resources>
<ResourceDictionary>
<AMSI:Global x:Key="AMSI.Global"/>
<eFin:Global x:Key="eFinancials.Global" />
<eService:Global x:Key="eService.Global" />
<eSite:Global x:Key="eSite.Global" />
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/ControlStyles.xaml"/>
<ResourceDictionary Source="Resources/DefaultColors.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Ok... great. I was happy. Until I tried to run the app and got an initialization error. Apparently it happens in the constructor of one of the above global objects where we have this code:
var amsiGlobal = Application.Current.Resources["AMSI.Global"] as AMSI.Global;
amsiGlobal.PropertyChanged += new
System.ComponentModel.PropertyChangedEventHandler(amsiGlobal_PropertyChanged);
It was no longer getting a reference to the AMSI.Global object... but it had been working fine before the move.
What am I doing wrong. If I move those global objects outside or the resource dictionaries the code runs again but blend tells me there is an error in the xaml, it also doesn't find the dictionaries when I try to create new control templates. Also, if I create control templates they don't seem to be found, even if they are on the same page as the control referencing it. So, I assume at runtime there will be an issue to.
Any ideas what is going on here? Do I just need to move all my styles and templates back to app.xaml?
I'm a bit new at silverlight, but, have you tried adding
<AMSI:Global x:Key="AMSI.Global"/>
<eFin:Global x:Key="eFinancials.Global" />
<eService:Global x:Key="eService.Global" />
<eSite:Global x:Key="eSite.Global" />
to the Merged Dictionaries?
it would look something like this
<Application.Resources>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<AMSI:Global x:Key="AMSI.Global"/>
<eFin:Global x:Key="eFinancials.Global" />
<eService:Global x:Key="eService.Global" />
<eSite:Global x:Key="eSite.Global" />
</ResourceDictionary>
<ResourceDictionary Source="Resources/ControlStyles.xaml"/>
<ResourceDictionary Source="Resources/DefaultColors.xaml"/>
</ResourceDictionary.MergedDictionaries>
I normally just add my resources in the merged dictionaies and never had a problem
Regards