WPF触发快乐帮助 [英] WPF Trigger Happy help
问题描述
我急需帮助.我有一个名为_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 aDependencyProperty
or normal property which utilizesINotifyPropertyChanged
.
Second only use a trigger if you''re already working with aStyle
, that is do not create aStyle
for a control for the sole purpose of adding triggers. If you do not already have aStyle
for some other purpose, then bind theVisibility
property of yourTextBox
es and use theBooleanToVisibilityConveter
.
为此,您将使用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屋!