将列表框项目索引作为参数传递给 objectdataprovider

发布于 2024-09-26 05:31:27 字数 1075 浏览 3 评论 0原文

我当前正在尝试使用对象数据提供程序返回我想用作每个列表框项目背景的颜色,该颜色取决于该列表框项目索引。

基本上,传递给对象的参数是原始颜色和 listboxitem 索引,并且它将根据索引返回更浅的颜色...这是我当前为对象数据提供程序提供的代码:

    <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>

我知道您不能进行直接绑定,因为它不是依赖项对象并且不符合绑定规则,并且您必须直接设置它...但是,我不确定我应该在列表框项 xaml 中的位置绑定回来。

此外,在长时间搜索这个问题的答案时,我只找到了一些例子,人们只根据诸如使用此方法在文本框中输入的内容等内容来更改参数:-

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

我希望它绑定到列表框索引,所以不确定将其放入哪个属性中。

第二个问题: 列表框项目确实有一个标签,其内容绑定到列表框项目索引,但是,当我总是想将其绑定到索引时,如何使用上述绑定源技术来绑定内容?

提前感谢您的帮助! =)

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! =)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

芯好空 2024-10-03 05:31:27

这可能看起来有点愚蠢,但是您是否考虑过使用后面的代码间接链接它?也就是说,使用一系列变量和选择案例来设置您想要的属性。我知道数据绑定可能会成为一个真正令人头痛的问题 - 如果有另一种方法可以实现完全相同的最终结果,通常我会避免它。

我真的需要更多关于你的最终目标是什么的细节(尽管可能我的咖啡还没有足够让我理解英语,哈哈)。您使用数据库吗?如何获得每个用户的排名?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文