我正在开发一个WPF应用程序,它会在单击按钮时创建新选项卡.这工作正常.我很难弄清楚如何设置关闭按钮,比如Tab标题旁边的X并关闭所选标签?
MainWindow.xaml
<Grid>
<StackPanel Name="listConnections" Grid.Column="0" Background="#4682b4" Margin="0,0,0,-0.2" >
</StackPanel>
<TabControl Name="tabConnections" Grid.Column="1" TabStripPlacement="Top" Margin="0,0,0.4,-0.2">
</TabControl>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
在按钮单击MainWindow.xaml.cs时添加Tab方法以创建新选项卡
public void addTab(Connection connection)
{
TabItem tab = new TabItem();
tab.Header = connection.name;
tabConnections.Items.Add(tab);
}
Run Code Online (Sandbox Code Playgroud)
有一个简单的方法来关闭按钮吗?
我正在使用Moq和Nunit Framework对我的Controller中的一个方法进行单元测试.我正在努力理解Mocking存储库和其他对象的概念,但没有取得多大成功.
我有一种方法,不允许用户删除在他/她的帐户中有未结余额的学生.该方法的逻辑在我的StudentController中,在POST方法中,我也使用存储库和依赖注入(不确定是否导致问题).当我运行我的单元测试时,有时它会转到我的GET Delete()方法,如果它进入POST method我得到一个错误,说"对象引用未设置为对象的实例"代码行说这个if (s.PaymentDue > 0)?
StudentController
public class StudentController : Controller
{
private IStudentRepository studentRepository;
public StudentController()
{
this.studentRepository = new StudentRepository(new SchoolContext());
}
public StudentController(IStudentRepository studentRepository)
{
this.studentRepository = studentRepository;
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Delete(int id)
{
//studentRepository.DeleteStudent(id);
Student s = studentRepository.GetStudentByID(id);
var paymentDue = false;
if (s.PaymentDue > 0)
{
paymentDue = true;
ViewBag.ErrorMessage = "Cannot delete student. Student has overdue payment. Need to CLEAR payment before deletion!"; …Run Code Online (Sandbox Code Playgroud)