Ronald Wildenberg
Ronald Wildenberg

Reputation: 32104

Check whether Image has source in XAML

I have the following lines of XAML:

<extToolkit:BusyIndicator IsBusy="<image source not set>">
    <Image Source="{Binding FirstSideImage,
                            Converter={StaticResource bitmapConverter}}" />
</extToolkit:BusyIndicator>

I would like the BusyIndicator's IsBusy property to depend on the availability of the Image's Source property. So if there is no image source, IsBusy should be true, otherwise false.

Is this somehow possible? I could of course have a separate property in my view model that does the same but I'd like to know if I can derive this directly from the image.

Upvotes: 1

Views: 290

Answers (1)

brunnerh
brunnerh

Reputation: 184622

You could apply a style to the BusyIndicator, assuming that the Image is the Content (i am not familiar with the control):

<extToolkit:BusyIndicator>
    <extToolkit:BusyIndicator.Style>
        <Style TargetType="extToolkit:BusyIndicator">
            <Setter Property="IsBusy" Value="False" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding Content.Source, RelativeSource={RelativeSource Self}}"
                        Value="{x:Null}">
                    <Setter Property="IsBusy" Value="True" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </extToolkit:BusyIndicator.Style>
    <Image Source="{Binding FirstSideImage,
            Converter={StaticResource bitmapConverter}}" />
</extToolkit:BusyIndicator>

You could also directly use the binding in the trigger and apply a converter which turns null into true.

Upvotes: 1

Related Questions