我实现了一个 WPF 按需加载树视图,就像这篇(非常好的)文章中描述的那样。在提到的解决方案中,使用一个虚拟元素来保留展开+图标/树状视图项的行为。当用户单击扩展器时,虚拟项目将替换为真实数据。
我想通过向public bool HasChildren { get { ... } }我的 backing添加一个属性来优化模型TreeNodeViewModel。
问题:
如何绑定此属性以隐藏/显示展开图标(在 XAML 中)?我找不到合适的触发器/设置器组合。
(INotifyPropertyChanged 已正确实施。)
谢谢你的时间。
更新 1:
我想使用我的属性public bool HasChildren 而不是使用虚拟元素。
确定一个物品是否有孩子的成本有点高,但仍然比去取孩子便宜得多。
我有下拉和网格.在网格列中有超链接.如果Dropdown集合包含1个项目,则下拉列表应该是不可见的.我需要一个逻辑来将Visibility绑定到项目集合.
这是GRid中一个超链接的XAML.
<!--Associate-->
<TextBlock Margin="10, 0, 0, 0">
<TextBlock.Visibility>
<MultiBinding Converter="{StaticResource courseListVisibilityConverter}"
ConverterParameter="Associate">
<Binding Path="IsCourseAssocited"
RelativeSource="{RelativeSource Mode=FindAncestor,AncestorType={x:Type DPA2:TakenCoursesNotApplied}}" />
<Binding Path="DataContext"
RelativeSource="{RelativeSource Self}" />
</MultiBinding>
</TextBlock.Visibility>
<Hyperlink DataContext="{Binding}"
Name="Associate"
IsEnabled="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TextBlock}}, Path=IsVisible}"
Click="Associate_Click">
<TextBlock TextWrapping="Wrap"
Text="Associate" />
</Hyperlink>
</TextBlock>
public class CourseListVisibilityConverter : IMultiValueConverter
{
public object Convert(object[] value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null || value[0] == null || value[1] == null) return Visibility.Collapsed;
bool IsEditMode = value[0] == DependencyProperty.UnsetValue ? …Run Code Online (Sandbox Code Playgroud)