Xaml question (1 Viewer)

doskabouter

Development Group
  • Team MediaPortal
  • September 27, 2009
    4,566
    2,938
    Nuenen
    Home Country
    Netherlands Netherlands
    Hi all,

    I've been investigating this for quite a while now, but I'm not having any success here.
    What I want to achieve is that I have a screen with a textbox on it, and an "Ok" and "Cancel" button.
    When the screen shows, it should display a dynamically generated text, and when I click "Ok" it should execute a method of my class with the entered text in a parameter.

    As a test, I added
    Code:
    private string te="testing";
    
      public string TestEdit
      {
      get { return te; }
      set { te = value; }
      }
    to the GuiTestModel.cs, and added
    Code:
    Text="{Binding Path=TestEdit, Mode=TwoWay}"
    as an attribute to one of the textboxes in test-virtualkeyboardcontrol.xaml in the GUITestPlugin's skin-folder
    Also tried
    Code:
    Text="{Binding Path=GUITestModel.TestEdit, Mode=TwoWay}"
    but none of those attempts shows "testing" in a textbox when I enter the "VirtualKeyboard test" screen.

    In the PartyMusicPlayer it does seem to work for the EscapePassword property, but I can't figure out what the missing piece in my guitestplugin is.

    This is only one aspect of my dialog, the other one is the okbutton triggering a method call with correct parameter, but perhaps if I understand what the issue is with my first test, I can manage to get the okbutton working. And if not, you'll be the first to know :)
     

    osre

    Retired Team Member
  • Premium Supporter
  • December 14, 2014
    775
    387
    Home Country
    Germany Germany
    You have to add the source to your binding like this:
    XML:
    Text="{Binding Source={StaticResource Model}, Path=TestEdit, Mode=TwoWay}"
    where the model resource is defined like this in your screen:
    XML:
    <Screen.Resources>
    <Model x:Key="Model" Id="F4FC1599-F412-40d0-82BF-46FC352E93BE"/>
    ...
    Also if you want to update the textbox when the property changes, then you need to define it as an WProperty (there are some in GUITestModel).

    A button should be defined like this:
    XML:
    <Button Style="{StaticResource ButtonWideStyle}" Content="My button"
    Command="{Command Source={StaticResource Model},Path=MyButtonHandler}"/>

    With a handler like this:
    Code:
    public void MyButtonHandler()
    in the GUITestModel.
     

    morpheus_xx

    Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,073
    7,459
    Home Country
    Germany Germany
    public string TestEdit
    {
    get { return te; }
    set { te = value; }
    }
    Also if you want to update the textbox when the property changes, then you need to define it as an WProperty (there are some in GUITestModel).

    What osre mentioned is very important:
    while binding to simple properties work this way, changed values are not visible to xaml! (no change events/listeners this way)

    you need always a combination of simple property ("TestEdit") and a WProperty with ("...Property"), where the xaml binds to.

    AbstractProperty _testEditProperty = new WProperty(typeof(string), null);
    public AbstractProperty TestEditProperty
    {
    get{ return _testEditProperty; }
    }
    public string TestEdit
    {
    get { return (string)_testEditProperty.GetValue(); }
    set { _testEditProperty.SetValue(value); }
    }

    Please check other models for example.
     

    doskabouter

    Development Group
  • Team MediaPortal
  • September 27, 2009
    4,566
    2,938
    Nuenen
    Home Country
    Netherlands Netherlands
    Wow, this is actually working! Thanks!

    Btw, I didn't need live changes being propagated, so osre's solution is good enough for now

    Another small step forward...

    Edit:
    Is there also a construct possible where I have a
    Code:
    public void MyButtonHandler(string s)
    combined with:
    Text="{Binding Source={Service WorkflowManager}, Path=CurrentNavigationContext.ContextVariables[StartValue]}"
    so that I don't have to reference a property of my class?

    Edit2: Thanks again for this nudge in the right direction. It seems that now I can implement it exactly the way I wanted!
     
    Last edited:

    doskabouter

    Development Group
  • Team MediaPortal
  • September 27, 2009
    4,566
    2,938
    Nuenen
    Home Country
    Netherlands Netherlands
    Just a small question:
    Is it possible to have a command with more than 1 parameter, and if so, what is the correct syntax?
    Couldn't find any example of that, so it may not even be possible...
    I'm after something like:
    Code:
    <KeyBinding Key="Left" Command="{Command Path=Scroll, Parameter1=-100, Parameter2=0}"/>
     

    osre

    Retired Team Member
  • Premium Supporter
  • December 14, 2014
    775
    387
    Home Country
    Germany Germany
    Parameters is a list of objects, which is passed in the same order to the command handler.
    But I dont know how to specify a list or an Array in XAML atm!?
    @morpheus_xx do you know how to do this?
     

    Users who are viewing this thread

    Top Bottom