的按钮,我有一个树视图启用选择treeveiw根节点
<TreeView HorizontalAlignment="Stretch" Name="tvLocations" VerticalAlignment="Stretch" />
和一个按钮
<Button Name="cmdUpdateLocation" Grid.Row="1" Content="Update" Width="80" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,88,0">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=tvLocations, Path=SelectedItem}" Value="{x:Null}">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
这将使该按钮,无论他们点击哪些树的水平。我希望在树视图中的某个项目被选中时启用按钮,但只有当它是根节点时才启用该按钮,或者如果它不是根目录,则禁用该按钮。我可以在XAML中检测他们选择的节点是否是根节点?
由于LPL,它似乎很奇怪,我认为没有内置的属性,以确定根节点。不过,我按照您的建议完成并实现了我自己的IsRootNode属性。有趣的博客btw。 – Fred