I’m trying to style a TreeView using this example and everything was working fine until I tried to add bindings to my DataContext. Namely, I replaced the Fill of the Paths for the arrows with a MultiBinding to the current theme. Here’s the relative code:
<Path x:Name="Collapsed" HorizontalAlignment="Left" VerticalAlignment="Center"
Margin="1" Data="M 4 0 L 8 4 L 4 8 Z">
<Path.Fill>
<SolidColorBrush>
<SolidColorBrush.Color>
<MultiBinding Converter="{StaticResource ThemeToColorConverter}"
ConverterParameter="Foreground">
<Binding Path="Themes" />
<Binding Path="ThemeIndex" />
</MultiBinding>
</SolidColorBrush.Color>
</SolidColorBrush>
</Path.Fill>
</Path>
I’ve set a breakpoint in the converter, and the problem seems to be that the two Bindings can’t find their Paths, because they both send null into the converter. However, I use this same code while setting the Button style earlier in the code, and the buttons show up perfectly.
The only thing I can think of is that, in the TreeView Style, the Bindings are pulling from a different source. I just don’t know how they would be doing that or how to fix it. Thanks!
Okay, I got it, so I’m posting my solution so anyone else with the same problem can (hopefully) find it. The problem was that the bindings were binding to the
TreeView Items, not theUserControl's DataContext, so I named theUserControland set theBindings' ElementNamesto that: