question

wirejp-9293 avatar image
0 Votes"
wirejp-9293 asked YonglunLiu-MSFT answered

Resources in ResourceDictionary require a x:Key attribute

I am building a Xamarin Forms app and I received an error message on the MainViewPage.xaml on line 10: -
Resources in ResourceDictionary require a x:Key attribute

 <?xml version="1.0" encoding="utf-8" ?>
 <FlyoutPage xmlns="http://xamarin.com/schemas/2014/forms"
              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"             
              xmlns:ff="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
              xmlns:vm ="clr-namespace:InventoryTrackerApp.ViewModels.Storage"
              x:Class="WineryTrackersApp.Views.Weather.MainViewPage"
              xmlns:pages="clr-namespace:InventoryTrackerApp.Views.Storage">
   <FlyoutPage.Resources>
     <pages:MainViewPageFlyout x:Name="FlyoutPage" />//Error message appears here
         <ResourceDictionary>
             <Color x:Key="MainColor">Black</Color>
             <Style TargetType="NavigationPage">
                 <Setter Property="BarBackgroundColor" Value="Black"/>
             </Style>
         </ResourceDictionary>
     </FlyoutPage.Resources>

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

YonglunLiu-MSFT avatar image
0 Votes"
YonglunLiu-MSFT answered

Hello,

You need to use x:key in your Resources part, such as:

<FlyoutPage.Resources>
     <pages:MainViewPageFlyout x:key="a_key" x:Name="FlyoutPage" />


You can refer to Xamarin.Forms resource dictionaries for a full explanation on how to use the attribute on your resources, and you could find this:

With the exception of implicit styles, each resource in resource dictionary must have a unique string key that's defined with the x:Key attribute.

That's the reason why the error occurs.

Best Regards,

Alec Liu.




If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.





5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.