Click here to Skip to main content
14,928,868 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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 .
Ace_Hardlight 18-Oct-11 15:21pm
Ok but how does the BooleanToVisibiltyConverter work?
Simon Bang Terkildsen 18-Oct-11 15:30pm
see WPF Tutorial - Binding Converters
BooleanToVisibilityConverter already exists so you don't have to create it yourself
[no name] 18-Oct-11 15:36pm
+5 You are completly right about not using the trigger. Nice catch!
Ace_Hardlight 18-Oct-11 15:38pm
Thank you so much :D used the article and now it works !! Thanks everyone that posted solutions. Appreciate it very much
Espen Harlinn 18-Oct-11 19:19pm
Excellent :)
Simon Bang Terkildsen 19-Oct-11 11:25am
Thank you, Espen.
For this you would use DataTriggers.

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

Also, your "Reprint" property needs to be public.
Simon Bang Terkildsen 18-Oct-11 15:19pm
A 4, it's important that the Reprint property actually notifies about changes. I've mentioned that in my solution.
[no name] 18-Oct-11 15:33pm
Good point. My brain must not be in the game today ;)
Simon Bang Terkildsen 18-Oct-11 15:39pm
hehe, happens to all of us now and then :)
Ace_Hardlight 18-Oct-11 15:19pm
This is what i have got but it doesn't work at all

<textbox grid.row="6" verticalalignment="Center"
="" name="txtDocNo" text="Doc No: " margin="3,61,610,46" grid.columnspan="2" grid.rowspan="2">
<Style TargetType="{x:Type TextBox}">
<datatrigger binding="{Binding Path= _Reprint}" value="False">
<setter property="Visibility" value="Visible">


[no name] 18-Oct-11 15:34pm
What you have posted is an empty collection of triggers. They will not do anything. Try the data trigger that I posted.
Ace_Hardlight 18-Oct-11 15:22pm
Doesn't want to display properly sorry

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900