I have a StackPanel
that holds a TextBox
with a title and an ItemsControl
with items. I'd like to hide the entire StackPanel if the list supplying the items is empty.
Instead of writing a dedicated Converter for the binding, I wanted to give QuickConverter (https://quickconverter.codeplex.com/) a try. QuickConverter allows to use inline C# expressions in bindings.
So this is my mark-up:
<StackPanel Visibility="{qc:Binding '$P > 0 ? Visibility.Visible : Visibility.Collapsed', P={Binding Path=Value.Count}}"> <!-- this does not work. It's always shown, regardless of the element count -->
<TextBlock Text="{qc:Binding '$P', P={Binding Path=Value.Count}}"></TextBlock> <!-- for debugging purposes only. It correctly shows the element count for the list -->
<TextBlock Text="{qc:Binding '$P.Count', P={Binding Path=Value}}"></TextBlock> <!-- for debugging purposes only. It should do the same as the line above, but it does nothing -->
...
<ItemsControl ItemsSource="{Binding Path=Value}">
...
</ItemsControl>
</StackPanel>
The first textblock is displaying the expected result, all other QuickConverter expressions fail to work. There are no errors or exception, neither at design time nor at runtime.
Thank you for any ideas.
Chris.
You may have a DataTrigger
in a Style
like this:
<StackPanel>
<StackPanel.Style>
<Style TargetType="StackPanel">
<Style.Triggers>
<DataTrigger Binding="{Binding Value.Count}" Value="0">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</StackPanel.Style>
...
</StackPanel>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With