【问题标题】:All binding with different index collection items update at the same time WPF与不同索引集合项的所有绑定同时更新 WPF
【发布时间】:2013-05-31 21:14:26
【问题描述】:

我的 WPF 视图中有这样的代码..

    <!--Column 2-->
    <Border Grid.Column="1" Grid.Row="1" >
        <TextBox x:Name="textB2BR0K2" Text="{Binding Path=ListBlok2B[0].B2B1}" />
    </Border>
    <TextBox x:Name="textB2BR1AK2" Grid.Column="1" Grid.Row="4" Text="{Binding Path=ListBlok2B[0].B2BR1A}"/>
    <TextBox x:Name="textB2BR1BK2" Grid.Column="1" Grid.Row="5" Text="{Binding Path=ListBlok2B[0].B2BR1B}"/>
    <TextBox x:Name="textB2BR1CK2" Grid.Column="1" Grid.Row="6" Text="{Binding Path=ListBlok2B[0].B2BR1C}"/>

    <!--Column 3-->
    <Border Grid.Column="2" Grid.Row="1" >
        <TextBox x:Name="textB2BR0K3" Text="{Binding Path=ListBlok2B[1].B2B1}" />
    </Border>
    <TextBox x:Name="textB2BR1AK3" Grid.Column="2" Grid.Row="4" Text="{Binding Path=ListBlok2B[1].B2BR1A}"/>
    <TextBox x:Name="textB2BR1BK3" Grid.Column="2" Grid.Row="5" Text="{Binding Path=ListBlok2B[1].B2BR1B}"/>
    <TextBox x:Name="textB2BR1CK3" Grid.Column="2" Grid.Row="6" Text="{Binding Path=ListBlok2B[1].B2BR1C}"/>

然后我从我的收藏中的数据库中填写了这个字段并正常工作。但是,当我尝试更改其中一个值时,所有具有某些绑定属性的数据都会同时更改 ListBlok2B[0].B2BR1AListBlok2B[1].B2BR1A 在我尝试在其中进行编辑时同时更改..

有人知道如何解决这个问题吗?我希望它绑定到我拥有的不同索引集合中,以便我可以将它插入我的数据库context.Blok2Bs.insertAllOnSubmit(ListBlok2B)

【问题讨论】:

    标签: wpf binding wpf-controls


    【解决方案1】:

    你为什么不使用 itemscontrol 并将你的集合绑定到它?

     <ItemsControl ItemsSource="{Binding ListBlok2B}>
       <ItemsControl.ItemTemplate>
        <DataTemplate>     
         <Grid>
          <Border Grid.Column="1" Grid.Row="1" >
             <TextBox x:Name="textB2BR0K2" Text="{Binding Path=B2B1}" />
          </Border>
          <TextBox Grid.Column="1" Grid.Row="4" Text="{Binding Path=B2BR1A}"/>
          <TextBox Grid.Column="1" Grid.Row="5" Text="{Binding Path=B2BR1B}"/>
          <TextBox Grid.Column="1" Grid.Row="6" Text="{Binding Path=B2BR1C}"/>
    
          </Grid>
        </DataTemplate>
       </ItemsControl.ItemTemplate>
     </ItemsControl>
    

    【讨论】:

    • 我昨天也尝试使用itemscontrol,但问题是我的控件是我用gridlayout创建的表格内的布局。它里面有一个标题。我怎样才能在其中制作标题模板物品控制?所以我的控件会因为它上面的网格位置而正确放置..?
    • 如果每一列都有一个标题,则可以将此标题信息添加到 itemssource 并将标题绑定也放入数据模板中。
    • add this header information 是什么意思?可以举个例子吗?
    • 我的意思是标题的名称,例如。 ListBlok2B[0].HeaderName = "Header1", ListBlok2B[1].HeaderName = "Header2" ...
    猜你喜欢
    • 2013-05-29
    • 2011-02-25
    • 2011-05-25
    • 2018-07-16
    • 1970-01-01
    • 2016-06-25
    • 1970-01-01
    • 2018-03-18
    • 1970-01-01
    相关资源
    最近更新 更多