简体   繁体   中英

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM