我正在尝试创建一个规则屏幕,用户可以在其中指定不同的规则,保存它们并稍后应用于数据。用户还可以对 AND OR 条件的规则进行分组。我的问题是这是否是正确的方法以及当用户单击删除时应该删除该行,我不知道该怎么做?
以下是我的 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.
}