Search code examples
xamlwinrt-xamluielementflyoutkaxaml

Why is this XAML failing with "The property "Content" can only be set once."?


I've got this XAML:

<AppBarButton Icon="Protected" Label="Privacy Policy" >
    <AppBarButton.Flyout>
        <StackPanel>
        <Flyout>
            <TextBlock Text="Photrax extracts information from images you load into it. The information it extracts includes location information (where the photos were taken, when that is available) and the date and time the photo was taken. This data is stored in a local/internal/embedded (SQLite) database. This data is not stored in the cloud but only on your local device." TextWrapping="Wrap" FontSize="26" FontFamily="Verdana">
            </TextBlock>
            <TextBlock Text="To reiterate: Your data is not shared with anyone else. It is stored only on the device from which you use Photrax." TextWrapping="Wrap" FontSize="26" FontFamily="Verdana">
            </TextBlock>
        </Flyout>
        </StackPanel>
    </AppBarButton.Flyout>
</AppBarButton>

...which fails with, "The property "Content" can only be set once."

Why is there a problem with this, when the following XAML, which is basically the same, compiles fine:

<AppBarButton Icon="MapPin" Label="Colors In Use" Tapped="appbarbtnPhotosetColorMapping_Tapped">
    <AppBarButton.Flyout>
        <Flyout>
            <StackPanel Background="Azure">
                <TextBlock Text="Photoset:Pushpin Color Legend" TextWrapping="Wrap" FontSize="26" FontFamily="Verdana"></TextBlock>
                <TextBlock x:Name="textblock0" Text="Unused" Foreground="Red" FontFamily="Segoe UI" FontSize="13" Margin="4" />

. . .

?

I get other err msgs with that xaml, too (about the following types being expected: flyoutbase and uielement), but I think it's the Content business that is giving me the business.

I pasted the problem code into kaxaml, but it doesn't even know what an AppBarButton is, and complained about that being an invalid element.

UPDATE

I can't test it yet, but I'm thinking that what Abdallah means is that I need to change this:

<StackPanel>
<Flyout>
  . . .
</Flyout>
</StackPanel>

...to this:

<Flyout>
<StackPanel>
. . .
</StackPanel>
</Flyout>

Solution

  • You have two problems here :

    1) The property "Content" can only be set once. :

    You can't set the content for <Flyout> </Flyout> more than once and you set the content twice (Two TextBlocks) in first XAML code and in the working XAML once(One StackPanel), According to MSDN :

    <Flyout>
        singleUIElement
    </Flyout>
    

    singleUIElement :

    A single object element that declares the content. This must be an object that has UIElement in its hierarchy (plain strings don't work). This can be a container, such as a Panel derived class, so that multiple content items within the Flyout can be arranged in layout.

    2) The following type was expected: "FlyoutBase".

    You can't set Flyout property to any class that not derived from FlyoutBase class (i.e only Flyout and MenuFlyout ). you set the Flyout property in first XAML code to StackPanel and in the working XAML to Flyout .