0
我想創建一個規則屏幕,用戶可以在其中指定不同的規則,稍後將它們保存在&以後應用於數據。用戶也可以將規則分組爲AND OR條件。我的查詢是,如果這是正確的做法&當用戶點擊刪除該行應該被刪除,我不知道該怎麼做?在Silverlight中動態添加/刪除網格中的行和控件
以下是我的XAML:
<Grid x:Name="LayoutRoot" Background="White" Width="600" Height="200" ShowGridLines="True">
<Grid.RowDefinitions><RowDefinition Height="30" /></Grid.RowDefinitions>
<Grid.ColumnDefinitions><ColumnDefinition Width="135"/><ColumnDefinition Width="25"/><ColumnDefinition Width="135"/><ColumnDefinition Width="135"/>
<ColumnDefinition Width="135"/><ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<telerik:RadComboBox Name="Header" Grid.Row="0" Width="100" HorizontalAlignment="Left">
<telerik:RadComboBoxItem Content="And" IsSelected="True"></telerik:RadComboBoxItem>
<telerik:RadComboBoxItem Content="Or"></telerik:RadComboBoxItem>
</telerik:RadComboBox>
<telerik:RadButton Content="+" Height="31" HorizontalAlignment="Left" Margin="106,0,0,0" Name="btnAdd" VerticalAlignment="Top" Width="26" Click="btnAdd_Click" />
</Grid>
而後面的代碼是:
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
var row = new RowDefinition();
row.Height = new GridLength(30);
LayoutRoot.RowDefinitions.Add(row);
var columnCombo = new Telerik.Windows.Controls.RadComboBox() { Width = 100, Height = 30, HorizontalAlignment = HorizontalAlignment.Left };
columnCombo.Items.Add("Column1");
columnCombo.Items.Add("Column2");
columnCombo.Items.Add("Column3");
var operatorCombo = new Telerik.Windows.Controls.RadComboBox() { Width = 100, Height = 30, HorizontalAlignment = HorizontalAlignment.Left};
operatorCombo.Items.Add("contains");
operatorCombo.Items.Add("startsWith");
operatorCombo.Items.Add("endsWith");
var btnRemove = new Telerik.Windows.Controls.RadButton() { Width = 20, Height = 30, Content = "X" };
btnRemove.Click += new RoutedEventHandler(btnRemove_Click);
var btnGroup = new Telerik.Windows.Controls.RadButton() { Content = "Group", Width = 50, Height = 30 };
btnGroup.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
btnGroup.Click += new RoutedEventHandler(btnGroup_Click);
var calendar = new Telerik.Windows.Controls.RadDatePicker();
LayoutRoot.Children.Add(btnRemove);
LayoutRoot.Children.Add(btnGroup);
LayoutRoot.Children.Add(columnCombo);
LayoutRoot.Children.Add(operatorCombo);
LayoutRoot.Children.Add(calendar);
int newrow = LayoutRoot.RowDefinitions.Count-1;
Grid.SetRow(btnRemove, newrow);
Grid.SetColumn(btnRemove, 1);
Grid.SetRow(columnCombo, newrow);
Grid.SetColumn(columnCombo, 2);
Grid.SetRow(operatorCombo, newrow);
Grid.SetColumn(operatorCombo, 3);
Grid.SetRow(calendar, newrow);
Grid.SetColumn(calendar, 4);
Grid.SetRow(btnGroup, newrow);
Grid.SetColumn(btnGroup, 5);
}
public void btnGroup_Click(object sender, RoutedEventArgs e)
{
throw new NotImplementedException();
}
public void btnRemove_Click(object sender, RoutedEventArgs e)
{
//TODO: Here I want to find out from which Gridrow user has clicked & remove that grid row & controls inside it.
}
感謝@zapico它的工作 – Deepak
將其標記爲接受的答案;-) – zapico