1
從它的外表下綁定刪除以前的組合框的SelectedItem我有一個ComboBox
和TextBox
像通過列表
<TextBlock Grid.Row="0" Grid.Column="0" TextAlignment="Center" VerticalAlignment="Center"
FontSize="16" FontWeight="Bold">Products :</TextBlock>
<ComboBox Grid.Row="0" Grid.Column="1" Margin="10" Height="30"
ItemsSource="{Binding Path=LstProducts}" SelectedItem="{Binding Path=Items.Product}"/>
<TextBlock Grid.Row="0" Grid.Column="2" TextAlignment="Center" VerticalAlignment="Center"
FontSize="16" FontWeight="Bold">Cost :</TextBlock>
<TextBox Grid.Row="0" Grid.Column="3" Margin="10" Height="30"></TextBox>
每次我創建這些控件我Button
點擊
<Button Grid.Row="1" Grid.Column="1" Margin="15" VerticalAlignment="Center" FontSize="12"
FontWeight="Bold" Click="ButtonBase_OnClick" Name="BtnAddmore">Add Rows</Button>
我結合我新上這樣
var ddlCurriency = new ComboBox
{
FontWeight = FontWeights.Bold,
Margin = new Thickness(7),
BorderBrush = Brushes.Black,
Name = "NewDdlCurrency" + _btncount
};
ddlCurriency.SetBinding(ItemsControl.ItemsSourceProperty, new Binding("Items.Product"));
按鈕點擊事件創建
我不想讓我以前的組合框選定的項目在列表中重複。
例如。 假設我的第一個Combobox包含項目列表(A,B,C,D)和我選擇的'B'並單擊了添加行 button。在我的下一個組合框列表中,我希望獲得Items(A,C,D ) 只要。
由於我使用MVVM和我LstProducts是我產品類我也試過這樣的,從這個列表中刪除所選的項目,但我也無法讓我的名單「LstProducts」
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
Button button = sender as Button;
Product obj = button.DataContext as Product;
obj.LstProducts.Remove(this.combo.SelectedItem.ToString());
}
是的,我試過這個通過使用我的代碼 obj.LstProducts.Remove(this.combo.SelectedItem.ToString()); –
@SabyasachiMishra我已編輯我的回答嘗試一個。 –
並嘗試使用Page/window DataContext而不是Buttondatacontext。 –