更改弹出按钮(UWP)的背景颜色

时间:2020-05-12 16:25:32

标签: xaml uwp uwp-xaml

我的页面上有一个弹出控件,我想更改它的背景色。我该如何实现?

 <Button x:Name="btn"  Background="Transparent">
            <Image HorizontalAlignment="Center" />
            <Button.Flyout  >
                <Flyout Placement="Left" >
                    <ListView  ItemsSource="{x:Bind DDLItemsSource, Mode=OneWay}" Background="Green" VerticalAlignment="Stretch"  
                               SelectionChanged="StudentsList_SelectionChanged" x:Name="StudentsList" SelectionMode="Extended"  HorizontalAlignment="Stretch"  >
                        <Style TargetType="ListViewItem">
                            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                        </Style>
                    </ListView>
                </Flyout>
            </Button.Flyout>
        </Button>

如果我为子元素提供Background,则它在弹出和子元素之间留有一个边距,因此不可接受。目前看起来像这样 enter image description here

1 个答案:

答案 0 :(得分:1)

要更改弹出框的背景颜色,可以尝试设置内部FlyoutPresenter的属性的外观,这些内部{{3}}表示弹出框的内容。例如:

<Button.Flyout>
    <Flyout Placement="Left">

        <Flyout.FlyoutPresenterStyle>
            <Style TargetType="FlyoutPresenter">
                <Setter Property="Background" Value="Green"/>
            </Style>
        </Flyout.FlyoutPresenterStyle>

        <ListView ItemsSource="{x:Bind DDLItemsSource, Mode=OneWay}" Background="Green" VerticalAlignment="Stretch"  SelectionChanged="StudentsList_SelectionChanged" x:Name="StudentsList" SelectionMode="Extended"  HorizontalAlignment="Stretch"  >
            <Style TargetType="ListViewItem">
                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            </Style>
        </ListView>
    </Flyout>
</Button.Flyout>