?
Solved

WP7 Binding on Multiple Conditions

Posted on 2013-01-10
5
Medium Priority
?
314 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

765 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