绑定ItemsControl的可见性

时间:2013-04-24 16:48:43

标签: c#

我使用以下代码片段来绑定ItemsControl的Visibility。

<ItemsControl x:Name="PART_ItemsControl"
        Margin="{Binding ExcelLikeFilterAdvVisibility, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource marginConverterForOldExcelLikeFiltering}, ConverterParameter=ItemsControl}"
        ItemsSource="{TemplateBinding ItemsSource}"
        Visibility="{Binding Path=Items.Count, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource itemsSourceCountConverter}}">

由于此代码段,我在输出窗口中收到以下错误。

错误:

System.Windows.Data Error: BindingExpression path error: 'Items' property not found on 'ToolTipsDemo.StocksViewModel' 'ToolTipsDemo.StocksViewModel' (HashCode=42842654). BindingExpression: Path='Items.Count' DataItem='ToolTipsDemo.StocksViewModel' (HashCode=42842654); target element is 'System.Windows.Controls.ItemsControl' (Name='PART_ItemsControl'); target property is 'Visibility' (type 'System.Windows.Visibility')..

1 个答案:

答案 0 :(得分:5)

Visibility="{Binding Path=Items.Count,
                     RelativeSource={RelativeSource Self},
                     UpdateSourceTrigger=PropertyChanged,
                     Converter={StaticResource itemsSourceCountConverter}}">