Solved

WP7 Binding on Multiple Conditions

Posted on 2013-01-10
5
301 Views
Last Modified: 2014-11-12
Hello,

I am new to programing for Windows Phones Mango.  I am trying to figure out how to do a view change based on multiple conditions using Binding.  I could do this with the code behind file, but I am trying to learn the correct way to program for Windows Phones.

Basiclly, the idea is I have a group of four red rectangle, and I want it to turn green when multiple conditions have been met (conditions are different for each rectangle).  Once all rectangles are green, I would like a button to become enabled.  

I am not looking for someone to give me the code, just point me in the right direction.  I have done the following google seraches with no sucess.

WP7 Mult Conditional Binding
Windows Phone MultiTriggers
Windows Phone Multi Conditional Triggers
etc....

I just dont know the keywords yet to find what I am looking for.  Thank  you in advanced.
0
Comment
Question by:paulpp
  • 3
  • 2
5 Comments
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
When you bind the property to the object, unfortunately that has to be done in the property and not in the xaml.
0
 
LVL 2

Author Comment

by:paulpp
Comment Utility
So, in my code behind file, lets say the trigger for one rectangle to turn green is two textboxes must contain valid data.  I would put an if statment in the Event Handler for Text Changed event for both textboxes.  Something like this:

if(textbox1.Text.Length >0 && textbox2.Text.Length >0)
   change fill of rectange

Or is there a better way of doing it.  I know there are Converters implementing IValueConverter, but I dont know if that is a possibility.  Thank you.
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
You can do something like this:

<TextBlock BackColor = {Binding ClassProperty} />


public class Whatever
{
    public string ClassProperty
    {
          if(true)
           {
                  return "Red";
            }
             else
              {
                     return "Blue";
               }
     }
}
0
 
LVL 2

Author Comment

by:paulpp
Comment Utility
Hello,

I tried listed above, but ran into a couple problems.  First off, this looks like a property, so it is expecting a get or set statment.  I tried it in the get statment because that seemed logical, and when I clicked on the check box it did not update.  I placed the code in the code behind file for the page.  What do I need to use to call this property.  Here is my code
        public string RectProperty
        {
            get
            {
                if (checkBox2.IsChecked == true)
                    return "Red";
                else
                    return "Blue";
            }
        }

XAML

           <Rectangle Height="126"
                       Name="rectangle1" 
                       VerticalAlignment="Top" 
                       Width="243"
                       Fill="{Binding RectProperty}">
             
            </Rectangle>

Open in new window


Thank you for your help.
0
 
LVL 48

Accepted Solution

by:
Mikal613 earned 300 total points
Comment Utility
The binding is when you call Set the DataSource of the control. usually when you bind a listview or a control like that.

On a single object you can just call

private void PageLoad() //the event after the page loads
{
      if (true)
                    rectangle1.Fill = "Red";
                else
                    rectangle1.Fill = "Blue";
}
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
You should read OS supplied guidelines before developing. I can't stress that enough. The guidelines will help you understand the reasons mobile app developers do what they do.  Apple is very particular when they review appstore submissions.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now