0

I have a situation where I'm trying to Multibind to a converter to change my foreground color based on an attached property. Specifically, the Selector.IsSelectionActive attached property.

Following the advice in these questions and this blog I've managed to get something together that almost works, but the critical piece (the attached property) doesn't get passed through correctly.

Here's what I have so far:

            <Label x:Name="Fish"  Style="{DynamicResource ItemLabel}" Content="{Binding Path=DisplayName}" Template="{DynamicResource moduleItem}" >
                <Label.Foreground>
                    <MultiBinding Converter="{StaticResource DisplayStatusConv}">
                        <Binding Path="DisplayStatus"/>
                        <Binding Path="(Selector.IsSelectionActive)" 
                                 RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=Label}"/>
                    </MultiBinding>
                </Label.Foreground>

But the second value I get passed is just a DependencyProperty.UnsetValue.

ASh
  • 34,632
  • 9
  • 60
  • 82
Isaac
  • 334
  • 1
  • 4
  • 12
  • 1
    linked questions use `RelativeSource={RelativeSource Self}`. but most likely Label doesn't set that Selector.IsSelectionActive property – ASh Apr 06 '23 at 20:41
  • That worked! I could swear I tried that at one point. I was thinking that if I used Self, it would try to look at the binding rather than the label, and I can confirm via Snoop that the property is indeed on the label. Does find ancestor stop at the first label it encounters? – Isaac Apr 06 '23 at 20:56
  • 1
    Note that *binding* a Label to a string results in very bad performance (unless the Binding.Mode is OneTime). Better use the highly optimized TextBlock to display a short text. – BionicCode Apr 06 '23 at 21:35
  • @BionicCode Thank you, good to know. In this case, the label consists of an image, a TextBlock, and another image. Would I be better off using a different container? – Isaac Apr 07 '23 at 19:39

0 Answers0