Problem with updating binding properties

Discussion in 'Plugin Development' started by d2Liks, February 27, 2012.

  1. d2Liks

    d2Liks New Member

    Joined:
    February 22, 2012
    Messages:
    7
    Likes Received:
    0
    Ratings:
    +0 / 0
    Home Country:
    Ukraine Ukraine
    How do I implement refreshing of binding properties in MediaPortal2 similarly to Wpf INotifyPropertyChanged? Property triggers only with app loading, and all following values of that property on the form aren't refreshing after that.


     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. Albert
    • Team MediaPortal

    Albert MP2 Developer

    Joined:
    February 18, 2008
    Messages:
    1,297
    Likes Received:
    1,125
    Gender:
    Male
    Occupation:
    Dipl.-Inform.
    Location:
    Freiburg im Breisgau, Germany
    Ratings:
    +1,130 / 1
    Home Country:
    Germany Germany
  4. d2Liks

    d2Liks New Member

    Joined:
    February 22, 2012
    Messages:
    7
    Likes Received:
    0
    Ratings:
    +0 / 0
    Home Country:
    Ukraine Ukraine
    cs:

    private AbstractProperty _loginContentVisibility;

    public AbstractProperty LoginContentVisibilityProperty
    {
    get { return _loginContentVisibility; }
    }

    public Visibility LoginContentVisibility
    {
    get { return (Visibility)_loginContentVisibility.GetValue(); }
    set { _loginContentVisibility.SetValue(value); }
    }

    public PluginsModel()
    {
    _loginContentVisibility = new WProperty(typeof(Visibility), null);
    //Although property is set to Collapsed after loading StackPanel will have value Visible. Where is a problem here?
    LoginContentVisibility = Visibility.Collapsed;
    }

    XAML:
    <StackPanel Visibility= "{Binding Path=LoginContentVisibility, Mode=TwoWay}" >
    ...
    ...
    </StackPanel>

    How should I implement the property so that I can manage Visiblity property for Xamle object?
     
  5. morpheus_xx
    • Team MediaPortal

    morpheus_xx Lead Dev MP2

    Joined:
    March 24, 2007
    Messages:
    10,940
    Likes Received:
    4,708
    Ratings:
    +6,747 / 11
    Home Country:
    Germany Germany
    Show System Specs
    you should check the Types first:
    • _loginContentVisibility = new WProperty(typeof(Visibility), null); <-- the null is the default, when not set. Your type Visibility.Collapsed looks like an Enum. You should use a proper default value of this enum.
    • you should check the binding: "{Binding Path=LoginContentVisibility, Mode=TwoWay}" isn't it enough to have only "{Binding Path=LoginContentVisibility}" ?
    I did not use the Visibility property yet (in fact I did not know it yet ;)), but when you like to control if the element should be visible, use the "IsVisible" property in favour (simple bool value).
     
  6. d2Liks

    d2Liks New Member

    Joined:
    February 22, 2012
    Messages:
    7
    Likes Received:
    0
    Ratings:
    +0 / 0
    Home Country:
    Ukraine Ukraine
    Problem isn't in Visibility only, any other properties don't refresh, get ccessors don't trigger, moreover binding works properly.

    One more question. How do I detect a click on the ListView element?

    How does next piece of code work?
    <ListView.Resources>
    <CommandBridge x:Key="Menu_Command" Command="{Binding Path=Command,Mode=OneTime}"/>
    </ListView.Resources>
     
  7. Albert
    • Team MediaPortal

    Albert MP2 Developer

    Joined:
    February 18, 2008
    Messages:
    1,297
    Likes Received:
    1,125
    Gender:
    Male
    Occupation:
    Dipl.-Inform.
    Location:
    Freiburg im Breisgau, Germany
    Ratings:
    +1,130 / 1
    Home Country:
    Germany Germany
    About the properties not refreshing, I have two comments:
    1) Your code seems well. I would guess your model isn't loaded/referenced correctly. In your previous postings, I saw you reference your model correctly per GUID so I think the problem is that you don't register the plugin in the plugin.xml file correctly. The SkinEngine can only load the model with a given GUID if it is registered using the <Model> element in plugin.xml.
    2) We currently don't support the visibility mode Collapsed at all. Collapsed and Hidden work exactly the same, that's why we always use the IsVisible property instead of the Visibility property.

    Did you try our example plugins in the Resources folder? Some things are explained there.
    It's sometimes hard to find a problem when the SkinEngine doesn't work as expected. You can look into the log output and for hard problems, you can switch on more log output in several classes, for example FrameworkElement, BindingMarkupExtension and some more. Sometimes, the only thing which helps is to debug the SkinEngine in the IDE.
    Furthermore, it might be easier to help you when you attach your complete plugin code.
     
  8. Albert
    • Team MediaPortal

    Albert MP2 Developer

    Joined:
    February 18, 2008
    Messages:
    1,297
    Likes Received:
    1,125
    Gender:
    Male
    Occupation:
    Dipl.-Inform.
    Location:
    Freiburg im Breisgau, Germany
    Ratings:
    +1,130 / 1
    Home Country:
    Germany Germany
    That code provides a dynamic resource which is accessed by a DynamicMarkupExtension which is used somewhere in the ListView style. The reference is in file OtherControls.xaml #224.
     
  9. d2Liks

    d2Liks New Member

    Joined:
    February 22, 2012
    Messages:
    7
    Likes Received:
    0
    Ratings:
    +0 / 0
    Home Country:
    Ukraine Ukraine
    Hod should i organize data refreshing to make xaml data change?
    Could you tell me if MediaPortal2 supports MVVM?

    Plugin:
    <Plugin
    DescriptorVersion="1.0"
    Name="Plugins"
    PluginId="C28ABD6B-9615-4512-B8DA-A04096F35628"
    Author="d2L"
    Copyright="d2L"
    Description="Sample plugin"
    PluginVersion="0.1">

    <Runtime>
    <Assembly FileName="Plugins.dll"/>
    </Runtime>

    <Register Location="/Models">
    <Model Id="5726DA5A-70D5-458f-AF67-611293D97912" Name="ViewModel" ClassName="Plugins.Models.PluginModel"/>
    </Register>

    <Register Location="/Resources/Skin">
    <Resource Id="PluginsSkin" Directory="Skin" Type="Skin"/>
    </Register>

    <Register Location="/Resources/Language">
    <Resource Id="PluginsLanguage" Directory="Language" Type="Language"/>
    </Register>
    </Plugin>

    cs:
    private AbstractProperty _country;

    public AbstractProperty CountryProperty
    {
    get { return _country; }
    }
    public string Country
    {
    get { return (string)_country.GetValue(); }
    set { _country.SetValue(value); }
    }

    public PluginModel()
    {
    _country = new WProperty(typeof(string), null);
    }

    //There should be refresh after pressing on a button, but nothing happens
    public void SendMessage()
    {
    Country="Message";
    }


    xaml:
    <!-- Contents -->
    <ControlTemplate x:Key="Contents_Template" >
    <DockPanel Context="{Model Id=5726DA5A-70D5-458f-AF67-611293D97912}" LastChildFill="False">


    <DockPanel.Resources>
    <Model x:Key="ViewModel" Id="5726DA5A-70D5-458f-AF67-611293D97912"/>
    </DockPanel.Resources>
    <Button Style="{ThemeResource ButtonWideStyle}" Width="90" Margin="5,0,0,0" Command="{Command SendMessage}"></Button>
    <Label Content="{Binding Path=Country, Mode=TwoWay}" />

    </DockPanel>
    </ControlTemplate>
     
Loading...

Users Viewing Thread (Users: 0, Guests: 0)

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice
  • About The Project

    The vision of the MediaPortal project is to create a free open source media centre application, which supports all advanced media centre functions, and is accessible to all Windows users.

    In reaching this goal we are working every day to make sure our software is one of the best.

             

  • Support MediaPortal!

    The team works very hard to make sure the community is running the best HTPC-software. We give away MediaPortal for free but hosting and software is not for us.

    Care to support our work with a few bucks? We'd really appreciate it!