[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

WP7 Binding on Multiple Conditions

Posted on 2013-01-10
5
Medium Priority
?
323 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 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month20 days, 3 hours left to enroll

872 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