【发布时间】:2019-02-02 18:29:33
【问题描述】:
代码如下:
Xaml:
<UserControl x:Class="Prototype.Forms.UserForm"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Prototype.Forms"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="400">
<Grid>
<DataGrid Name="MainGrid">
</DataGrid>
</Grid>
</UserControl>
C#:
public partial class UserForm : UserControl
{
public UserForm(IList <Element> list)
{
InitializeComponent();
DataTable dt = new DataTable();
dt.Columns.Add(" ",typeof(bool));
dt.Columns.Add("Iteration");
dt.Columns.Add("View name");
dt.Columns.Add("Type");
for (int i = 0; i < list.Count; i++)
{
DataRow r = dt.NewRow();
r[1] = i.ToString();
r[2] = list[i].Name;
r[3] = "some element type";
dt.Rows.Add(r);
}
MainGrid.ItemsSource = dt.DefaultView;
MainGrid.MouseLeftButtonUp += new MouseButtonEventHandler(CellClick);
}
private void CellClick(object sender, EventArgs e)
{
//Do stuff
}
}
所以我遇到的问题是我似乎无法检查多个复选框。一旦我尝试选中第二个复选框,之前选中的复选框就会变为未选中状态。
鼠标按钮事件是尝试使复选框保持选中状态但失败的尝试失败。
【问题讨论】:
-
根据tagging,我已从您的问题标题中删除了您的 C# 和 WPF 标签。
-
您能描述一下如何重现您的问题吗?我在您提供的代码中没有看到它。
-
看看你对应的xaml代码会很有帮助
-
@dontbyteme: 还有
CellClick()内部发生的事情