Search code examples
wpfxamlstylesxceed

WPF Exceed busyindicator + listbox combination style issues


I am using xceed busyindicator control and listbox with the very simple example. So i have background color of listbox set to black and when isbusy property of busyindicator is set to true. Listbox background color changes to white but for the rest of the control like grids background color remains the same. See example below. I want my listbox color to remain same as what i set but its changes to white when 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>

Solution

  • The BusyIndicator has by default a semi-transparent Overlay. Also, it sets the underlying element's IsEnabled=False

    You can achieve what you want like this:

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