【问题标题】:Is it enough to set Binding Mode in ItemsSource?在 ItemsSource 中设置 Binding Mode 是否足够?
【发布时间】:2011-06-05 05:07:14
【问题描述】:

这是多余的吗(每个TextBlock 中的Mode=OneTime)?

            <ListBox ItemsSource="{Binding Path=SearchResultsItems, Mode=OneTime}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                            <StackPanel>
                                <TextBlock Text="{Binding Path=Price, Mode=OneTime}" />
                                <TextBlock Text="{Binding Path=Description, Mode=OneTime}" />
                            </StackPanel>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

【问题讨论】:

    标签: wpf silverlight binding binding-mode


    【解决方案1】:

    我不这么认为。将ItemsSource 设置为OneTime 涉及项目的集合,而不是项目本身。 ItemsSource = OneTime 真正的意思是“如果初始化后项目集合发生变化,请不要更新我的 ListBox”。

    【讨论】:

      【解决方案2】:

      我不这么认为。

      如果 itemssource 上的绑定为 OneTime 模式,则在更改列表(添加或删除项目)时不应更改属性,但仍会从列表项的属性中更改属性。

      因此,如果您不想在商品上显示价格或描述更改,则应在文本块上保留 Mode=OneTime。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-04-21
        • 2023-04-01
        • 2016-03-29
        • 1970-01-01
        • 2012-03-30
        • 2023-03-15
        • 2018-04-11
        相关资源
        最近更新 更多