Resources in ResourceDictionary require a x:Key attribute

wire_jp 206 Reputation points

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=""
             xmlns:vm ="clr-namespace:InventoryTrackerApp.ViewModels.Storage"
    <pages:MainViewPageFlyout x:Name="FlyoutPage" />//Error message appears here
            <Color x:Key="MainColor">Black</Color>
            <Style TargetType="NavigationPage">
                <Setter Property="BarBackgroundColor" Value="Black"/>
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,313 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 37,581 Reputation points Microsoft Vendor


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

            <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.

    0 comments No comments

0 additional answers

Sort by: Most helpful