我正在使用 WPF(4.5) 和 Caliburn.Micro。我试图了解如何让我的 View 中的“事件”操纵我 View 中的其他控件。
例如:
我的 View 有一个扩展控件、一个按钮和一个 GridView。 GridView 位于 Expander 内。当用户单击该按钮时,它会调用 VM 中的一个方法,该方法使用 BindableCollection<> 填充 gridview。我想要发生的是,当该集合有超过 1 个项目时,我想自动展开 Expander Control。
想法?
请您参考如下方法:
您可以绑定(bind)到集合中的项目数:
<Expander IsExpanded="{Binding Path=YourCollection.Length, Converter={StaticResource ResourceName=MyConverter}" />
然后在窗口或用户控件中:
<UserControl... xmlns:converters="clr-namespace:My.Namespace.With.Converters">
<UserControl.Resources>
<converters:ItemCountToBooleanConverter x:Key="MyConverter" />
</UserControl.Resources>
</UserControl>
和转换器:
namespace My.Namespace.With.Converters {
public class ItemCountToBooleanConverter : IValueConverter
{
// implementation of IValueConverter here
...
}
}
这是我凭空写的,如果有错误,请见谅;)
此外:确保您的 viewModel 实现了 INotifyPropertyChanged 接口(interface),但我假设您已经知道了。
