【发布时间】:2014-06-02 23:38:49
【问题描述】:
拥有一个用户控件模板SubCtrl,它在构造函数上获取一个id
设置标签CounterLabelText 并包含:
1 个复选框
1 个按钮
1 RadNumeric
<Grid Height="27" Width="602">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="533*" />
<ColumnDefinition Width="44*" />
</Grid.ColumnDefinitions>
<Label Margin="26,0,492,0" Content="{Binding CounterLabelText}" />
<CheckBox Height="16" HorizontalAlignment="Left" Margin="7,5,0,0" Name="ChkBxOrder" Width="21" VerticalAlignment="Top" telerik:StyleManager.Theme="Vista" IsManipulationEnabled="True" />
<!--<telerik:RadButton Height="22" HorizontalAlignment="Left" Margin="343,1,0,0" Name="ButtonDoSomething" Width="58" VerticalAlignment="Top" telerik:StyleManager.Theme="Vista" Content="Set Points" Click="ButtonDoSomething_Click" />-->
<telerik:RadNumericUpDown Height="18" HorizontalAlignment="Left" Margin="412,1,0,0" Name="radx" Width="40" VerticalAlignment="Top" IsInteger="True" telerik:StyleManager.Theme="Vista"/>
</Grid>
public partial class SubCtrl : UserControl
{
private string _counterLabelText;
public string CounterLabelText
{
get
{
return _counterLabelText;
}
set
{
_counterLabelText = value;
OnPropertyChanged("CounterLabelText");
}
}
public SubCtrl(int id)
{
InitializeComponent();
CounterLabelText = id.ToString();
DataContext = this;
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
由于用户控件是在主窗体内的ADD button 上动态创建的,因此传递了一个计数器,例如
public partial class MainCtrl : UserControl
{
int templateRowsCounter;
//constructor and variables
//...
//...
private void AddTemplate_Click(object sender, RoutedEventArgs e)
{
StackRefinement.Children.Add(new SubCtrl (++templateRowsCounter));
}
private void DelTemplate_Click(object sender, RoutedEventArgs e)
{
//how to remove it based on templateRowsCounter ???
}
}
我有两个问题
- 如何使用 DelTemplate_Click() 添加删除最后添加的模板?
-
SubCtrl带有一个复选框、一个按钮和一个 radNumeric 我怎么知道何时必须调用 ButtonDoSomething_Click() 方法 当按下ButtonDoSomething时,以及如何获取复选框和RadNumeric的状态,我的意思是如何检测事件?
【问题讨论】:
-
您尝试
ButtonBase.Click参加活动了吗? DelTemplate_Click 上应该删除哪个控件?第一,最后还是有任何选择? -
我想删除上次添加的模板,您能否举例说明如何在这种情况下为事件应用
ButtonBase.Click? -
我添加了问题 1 的答案,第二个我需要一些时间来准备