Solved

WP7 Binding on Multiple Conditions

Posted on 2013-01-10
5
310 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Preface: This article is part of a series focused on cross platform mobile app development (specifically Android and iOS) using the Alloy framework and Titanium Studio made by Appcelerator (https://www.appcelerator.com/). This article presumes a wor…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 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