WPF 超出忙指示器 + 列表框组合样式问题



我正在使用xceed繁忙指示器控件和列表框,其中包含非常简单的示例。所以我将列表框的背景颜色设置为黑色,当繁忙指示器的繁忙属性设置为 true。列表框背景色更改为白色,但对于控件的其余部分(如网格(,背景颜色保持不变。请参阅下面的示例。我希望我的列表框颜色与我设置的颜色保持不变,但是当 isBusy =true 时它会变为白色。

<Grid Margin="10">
    <xctk:BusyIndicator IsBusy="True">
        <Grid Background="Black">
            <Grid.RowDefinitions>
                <RowDefinition Height="0.50*" />
                <RowDefinition Height="0.50*" />
            </Grid.RowDefinitions>
            <ListBox Background="Black" Foreground="White">
                <ListBoxItem>ListBox Item #1</ListBoxItem>
                <ListBoxItem>ListBox Item #2</ListBoxItem>
                <ListBoxItem>ListBox Item #3</ListBoxItem>
            </ListBox>
        </Grid>
    </xctk:BusyIndicator>
</Grid>

默认情况下,BusyIndicator有一个半透明的覆盖层。此外,它还设置基础元素的IsEnabled=False

你可以像这样实现你想要的:

     <Grid Margin="10">
        <Grid.Resources>
            <Style x:Key="_BlackListBoxStyle" TargetType="{x:Type ListBox}">
                <Setter Property="Background" Value="Black" />
                <Setter Property="Foreground" Value="White" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ListBox}">
                            <Grid Width="Auto" Height="Auto">
                                <Border x:Name="Border" CornerRadius="0,0,0,0" />
                                <ScrollViewer
                                    Focusable="false"
                                    HorizontalScrollBarVisibility="Disabled"
                                    IsTabStop="False"
                                    >
                                    <StackPanel IsItemsHost="true" />
                                </ScrollViewer>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="BorderThickness" Value="0,0,0,0" />
            </Style>
        </Grid.Resources>
        <xctk:BusyIndicator IsBusy="True">
            <Grid Background="Black">
                <Grid.RowDefinitions>
                    <RowDefinition Height="0.50*" />
                    <RowDefinition Height="0.50*" />
                </Grid.RowDefinitions>
                <ListBox IsEnabled="False" Style="{StaticResource _BlackListBoxStyle}">
                    <ListBoxItem>ListBox Item #1</ListBoxItem>
                    <ListBoxItem>ListBox Item #2</ListBoxItem>
                    <ListBoxItem>ListBox Item #3</ListBoxItem>
                </ListBox>
            </Grid>
            <xctk:BusyIndicator.OverlayStyle>
                <Style TargetType="Rectangle">
                    <Setter Property="Fill" Value="Transparent" />
                </Style>
            </xctk:BusyIndicator.OverlayStyle>
        </xctk:BusyIndicator>
    </Grid>