开发者

passing listbox item index as parameter to objectdataprovider

开发者 https://www.devze.com 2023-01-18 18:25 出处:网络
I am currently attempting to use an object data provider to return the colour that I would like to use as a background for each listbox item, with the colour dependent on that listbox items index.

I am currently attempting to use an object data provider to return the colour that I would like to use as a background for each listbox item, with the colour dependent on that listbox items index.

Basically the parameters passed to the object is the original colour and the listboxitem index, and it will return a colour that is lighter based on what index it is... here is the code i have currently for the object data provider:

    <ObjectDataProvider ObjectType="{x:Type local:cUserProfiles}"
              MethodName="GetRankColour" x:Key="RankColour">
        <ObjectDataProvider.MethodParameters>
            <Color> {ORIGINAL_COLOUR}<Color/>
            <system:Int16>{LISTBOXITEM INDEX}</system:Int16>
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>

I am aware that you cannot do a direct bind because it is not a dependency object and does not conform to the rules for binding, and that you must set it directly... however, i'm not sure where in my listbox item xaml I am supposed to bind back.

Furthermore, upon a long search for the answer to this, I have only found examples where people only change the parameters based on things such as what someone enters into a textbox using this method:-

{Binding Source={StaticResource RankColour},   
                 Path=MethodParameters[1],  
                 BindsDirectlyToSource=True,  
                 UpdateSourceTrigger=PropertyChanged}

I want it to be bound to the listbox index, so not sure what property to put that into.

开发者_如何学运维Second question: The listbox item does have a label who's content is bound to the listbox item index, however, how can I use the above binding source technique to bind the content, when i always want to bind it to the index?

Thanks for your help in advance! =)


This may seem kinda silly, but have you thought about indirectly linking this using the code behind? That is, using a series of variables and select cases to set the properties you want to. I know that databinding can get to be a real headache - I avoid it if there is another way to pull off the exact same end result, usually.

I really could need a little more detail on what your end goal is (though it could be that my coffee hasn't kicked in enough for me to comprehend English yet, lol). Are you using a database? How do you get the rank for each user?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号