Solved

WP7 Binding on Multiple Conditions

Posted on 2013-01-10
5
304 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
ID: 38765695
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
ID: 38766009
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
ID: 38766740
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
ID: 38768214
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
ID: 38768244
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are anything like me, you install many apps on your phone and have your life on it, sometimes literally.  When I bought my current phone, a Samsung Galaxy S5 from Verizon, they were only selling the versions with 16 GB internal.  I didn't rea…
As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
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…

920 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

18 Experts available now in Live!

Get 1:1 Help Now