Ucercontrol 在数据模板中所有对象都会自动“共享”。
所以我得到了一个绑定到列表的选项卡控件(具有名称和代码)。这工作得很好
<TabControl.ContentTemplate>
<DataTemplate>
<sp:ucercontroltest DataContext="{Binding}" strname="{Binding Path=name}" strcode="{Binding Path=code}" />
</DataTemplate>
</TabControl.ContentTemplate>
但是如果我在 usercontroltest 上添加一个带有事件的按钮(btntestbutton),如果单击该按钮我希望禁用该按钮(btntestbutton.IsEnabled = false),那么它会在所有用户控件上被禁用(标签)!我怎样才能防止它被彼此共享,例如,如果我想禁用 1 个用户控件上的按钮,这样我就不会自动禁用所有这些按钮。
So I got a tabcontrol that is bound to an list(has name and code). And this is working perfectly
<TabControl.ContentTemplate>
<DataTemplate>
<sp:ucercontroltest DataContext="{Binding}" strname="{Binding Path=name}" strcode="{Binding Path=code}" />
</DataTemplate>
</TabControl.ContentTemplate>
But if I would add a Button(btntestbutton) on usercontroltest with an event, that if the button is clicked I want the button to be disabled (btntestbutton.IsEnabled = false) then it gets disabled on ALL the usercontrols(tabs)! How can I prevent it from all being shared wich each other so If I for example want to disable the button on 1 usercontrol so that I don t automaticly disable all of them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知
TabControls
重用从ContentTemplate
创建的控件,获得选项卡特有状态的一种方法是绑定IsEnabled
> 将按钮的属性设置为每个选项卡的虚拟机上的属性,然后状态将在选项卡切换时进行调整。 (当然,您随后需要调整处理程序中的 VM 属性,而不是IsEnabled
)As far as i know
TabControls
reuse the controls created from theContentTemplate
, one way to have a state unique to the tabs would be to bind theIsEnabled
property of the button to a property on the VM of each tab, then the state would adjust on tab-switch. (Of course you then would need to adjust the VM property in the handler, not theIsEnabled
)