tags:

views:

35

answers:

2

I want to set a label (or textbox) default string as long as the binding value is null. This works fine for any other property than content, for example:

        <Label Content="{Binding Source={StaticResource pumpCurvesViewSource}, Path=/Label}">
            <Label.ContentStringFormat>Details for pump curve: {0}</Label.ContentStringFormat>

            <Label.Style>
                <Style TargetType="Label" BasedOn="{StaticResource header}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Source={StaticResource pumpCurvesViewSource}, Path=/}" Value="{x:Null}">
                            <Setter Property="Background" Value="Red"></Setter>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Label.Style>
        </Label>

The above will change the background of the label to red as long as there is no CurrentItem in the "pumpCurvesViewSource", but what I really want to do is change the background trigger to this:

                            <Setter Property="Content" Value="No pump curve selected"></Setter>

But this does not work (I'm guessing it is because the Content is already bound and my setting would override the binding).

Does anyone know how to accomplish this?

A: 

Hi,

have you tried TargetNullValue?

<Label Content="{Binding Source={StaticResource pumpCurvesViewSource}, Path=/Label,  TargetNullValue='No pump curve selected'}">
decyclone
TargetNullValue did not work, besides its not a property on the bindingsource which returns a null value, its the binding itself
Marius
A: 

If found a way of accomplishing the same thing, but with a bit more code than I liked:

            <Label Content="{Binding Source={StaticResource pumpCurvesViewSource}, Path=/Label}">
                <Label.ContentStringFormat>Details for pump curve: {0}</Label.ContentStringFormat>
                <Label.Style>
                    <Style TargetType="Label" BasedOn="{StaticResource header}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Source={StaticResource pumpCurvesViewSource}, Path=/, Mode=OneWay, Converter={StaticResource isNullConverter}}" Value="True">
                                <Setter Property="Visibility" Value="Collapsed"></Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Label.Style>
            </Label>

            <Label Content="No pump curve selected">
                <Label.Style>
                    <Style TargetType="Label" BasedOn="{StaticResource header}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Source={StaticResource pumpCurvesViewSource}, Path=/, Mode=OneWay, Converter={StaticResource isNullConverter}}" Value="False">
                                <Setter Property="Visibility" Value="Collapsed"></Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Label.Style>
            </Label>
Marius