Resources in ResourceDictionary require a x:Key attribute

wire_jp 206 Reputation points
2022-04-22T05:17:10.9+00:00

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>
Xamarin
Xamarin
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
    2022-04-22T06:29:37.29+00:00

    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful