The Media Center Sandbox

Resources and discussion for developing experiences in the Windows Media Center platform.
Welcome to The Media Center Sandbox Sign in | Join | Help
in Search

Question on basic binding

Last post 08-26-2010, 11:13 PM by thus. 5 replies.
Sort Posts: Previous Next
  •  08-26-2010, 12:40 AM 9846

    Question on basic binding

    Hi

    This is perhaps a basic question but fail to find any good documentation.

    Task is to have a class with a caption, like this

    Foo foo = new Foo();
    foo.Caption = "Bar";

    Then have mcml show a label with this caption is easy. But when i change the member object "foo" to point to a new instance of type Foo then the caption on the label does not change.

    In short how do i from code tell the mcml that the object it shows has changed.

    I did get it to work on repeaters where it has a list as source. Then changing the content of the list did not work from code unless i made a list.Clear() first. E.g. you could simply say list[0] = new (); did not show any change. List.Clear() and then add a object made the list change.

    So is there a guideline for changing objects from code that is used in MCML?

    Thanks

    Kim
  •  08-26-2010, 2:08 AM 9847 in reply to 9846

    Re: Question on basic binding

    All I know is, MCML Rules can't handle the current changed data in code behind. You can get data from code behind in MCML but you can't bind the C# classes, properties etc. with changed rules and condition rules in MCML.

    Only MCML elements can be bind to the Rules.

    However you can handle your MCML elements from code behind. As I stated getting changed values from code behind with using the MCML rules is not possible. You have to write tricks like using static variables etc.

    If it is possible I will be learn as well :)
  •  08-26-2010, 6:48 AM 9848 in reply to 9847

    Re: Question on basic binding

    If you bind a "ArrayListDataSet" to a repeater and by codebehind clear the list and add new items, then it updates fine.

    Doing the same thing with a Text and a string does not.

    Sould also say that all the classes enherit from ModelItem.

    And yes using locals would be fine, but i can still not get it to work.

    Br

    Kim
  •  08-26-2010, 12:49 PM 9849 in reply to 9848

    Re: Question on basic binding

    Now i got it working.

    What i got wrong was that I expected that properties and locals that got initialized in the definitiion does not keep the relationship. So just defining a local and then creating a binding rule made it work.

    So now you can by code change any value and it gets reflected in the UI.
  •  08-26-2010, 10:49 PM 9850 in reply to 9847

    Re: Question on basic binding

    thus:
    All I know is, MCML Rules can't handle the current changed data in code behind. You can get data from code behind in MCML but you can't bind the C# classes, properties etc. with changed rules and condition rules in MCML.

    Only MCML elements can be bind to the Rules.

    However you can handle your MCML elements from code behind. As I stated getting changed values from code behind with using the MCML rules is not possible. You have to write tricks like using static variables etc.

    If it is possible I will be learn as well :)


    Just as an FYI - you *can* change data in your code and have it update in your MCML - this is the basis of the property system in MCML. You need to let Media Center know you want specific values tracking using and also use FirePropertyChanged in your code to let the property system know that the change has occurred. Items to bind that you want property notifications to work on should inherit from ModelItem.

    See the sample apps in the SDK for more examples of this.

    Cheers,
    Andrew
  •  08-26-2010, 11:13 PM 9851 in reply to 9850

    Re: Question on basic binding

    I found an example. This is from "STEVEN HARDING Programming in Vista Media Center" .pdf:

    public class ClickCounter2 : ModelItem
    {
    int m_Value;
    Command m_Increment;
    public String Value
    {
    get { return m_Value.ToString(); }
    set { m_Value = Value; FirePropertyChanged(“Value”); }
    }
    public Command Increment()
    {
    get { return m_Increment; }
    }
    public ClickCounter2()
    {
    m_Increment = new Command();
    m_Increment.Invoked += new
    EventHandler(IncrementButtonClicked);
    }
    public IncrementButtonClicked()
    {
    Value += 1;
    }
    }
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems