WPF触发快乐帮助 [英] WPF Trigger Happy help

查看:73
本文介绍了WPF触发快乐帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我急需帮助.我有一个名为_Reprint的变量,该变量在名为打印"的项目中的类Print构造函数中设置为true或false.然后,我在另一个名为Controls的项目中拥有一个打印屏幕视图.如果_Reprint = false,我想将此屏幕上的文本框设置为可见.如何在xaml中执行此操作?我知道这与触发器有关,但我似乎无法正确地做到这一点.这两个项目都包含在一个名为PrintingExpo的大项目中.希望我的问题足够清楚.在此先感谢

Hi guys I need help urgently. I have a variable _Reprint which is set to true or false in my class Print constructor in a project called Printing. Then i have a printscreen view in another project called Controls. I want to set textboxes on this screen to visible if the _Reprint = false. How do i do this in xaml? I know it''s to do with triggers but i can''t seem to get it right. Both projects are contained in one big project called PrintingExpo. Hope my question is clear enough. Thanks in advance

推荐答案

首先,您必须具有一个DependencyProperty或使用INotifyPropertyChanged的常规属性.

其次,如果您已经在使用Style,则仅使用触发器,即仅出于添加触发器的目的而不会为控件创建Style.如果您还没有Style用于其他用途,请绑定TextBox es的Visibility属性并使用BooleanToVisibilityConveter.
First of you must have a property which is either a DependencyProperty or normal property which utilizes INotifyPropertyChanged.

Second only use a trigger if you''re already working with a Style, that is do not create a Style for a control for the sole purpose of adding triggers. If you do not already have a Style for some other purpose, then bind the Visibility property of your TextBoxes and use the BooleanToVisibilityConveter .


为此,您将使用DataTriggers.

For this you would use DataTriggers.

<style>
   <datatrigger binding="{Binding Path=Reprint}">
        <setter property="Visibility" value="Visible" />
   </datatrigger>
</style>



另外,您的转载"属性必须是公开的.



Also, your "Reprint" property needs to be public.


这篇关于WPF触发快乐帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆