Wpf DAL生成器:如何获取网格复选框?
我正在建造一个WPF D.a.L.发电机 在我的主页中,我有一个DataGrid,其中填充了数据库中的表列表 我还有一个额外的复选框列,名为Wpf DAL生成器:如何获取网格复选框?,wpf,vb.net,checkbox,datagrid,data-access-layer,Wpf,Vb.net,Checkbox,Datagrid,Data Access Layer,我正在建造一个WPF D.a.L.发电机 在我的主页中,我有一个DataGrid,其中填充了数据库中的表列表 我还有一个额外的复选框列,名为ShouldInclude?我打算用它来确定表是否应该包含在生成中。。。是,如果选中,则不勾选 因为我正在用一些基本信息的强类型列表填充DataGrid的ItemSource,这些基本信息包括TableName、Schema、Columns,所以我现在不知道如何获得复选框的checked值,以便确定是否包含它 以下是构建表的函数,用于键入类代码文件: Pri
ShouldInclude?
我打算用它来确定表是否应该包含在生成中。。。是,如果选中,则不勾选
因为我正在用一些基本信息的强类型列表填充DataGrid的ItemSource
,这些基本信息包括TableName、Schema、Columns
,所以我现在不知道如何获得复选框的checked
值,以便确定是否包含它
以下是构建表的函数,用于键入类代码文件:
Private Sub GenerateTyping(ByVal _DG As DataGrid)
For Each i As TableTyping In _DG.Items
'check if should be generated
Dim _TString As String = String.Empty
Using _sr As New StreamReader(Common.GetPath() & "Class Templates\CSharp\Typing\XXX_Typing.txt")
_TString = _sr.ReadToEnd()
_sr.Close()
End Using
Dim _FN As String = i.Name & "_Typing.cs"
Dim _Props As New StringBuilder()
Dim _CL As List(Of ColumnTyping) = i.Columns
For Each col In _CL
With _Props
Dim _PropStr As String = "public " & Common.GetClrType(col.Type) & " " & col.Name & " { get; set; }"
.AppendLine(" " & _PropStr)
End With
Next
'Write the new class files
_TString = _TString.Replace("##TABLENAME##", If(i.Schema.Length > 0, i.Schema & "_", "") & i.Name).Replace("##THE_PROPERTIES##", _Props.ToString())
If Not Directory.Exists(FilePath & "\Typing\") Then
Directory.CreateDirectory(FilePath & "\Typing\")
End If
Using _sw As New StreamWriter(FilePath & "\Typing\" & If(i.Schema.Length > 0, i.Schema & "_", "") & i.Name & "_Typing.cs", False)
_sw.Write(_TString)
_sw.Close()
End Using
_TString = String.Empty
_Props.Clear()
Next
End Sub
Partial Public Class TableTyping
Public Property ID As Integer
Public Property Name As String
Public Property Schema As String
Public Property Columns As List(Of ColumnTyping)
End Class
Partial Public Class ColumnTyping
Public Property ID As Integer
Public Property Name As String
Public Property Type As SqlDataType
Public Property Length As Integer
Public Property DefaultValue As String
Public Property Precision As Integer
Public Property Scale As Integer
End Class
我的datagrid仅由3列组成<代码>包含?,表架构,表名称,通过以下方式填充:
<DataGrid EnableRowVirtualization="True" Name="dgTables" IsReadOnly="True" AutoGenerateColumns="False" FontFamily="Calibri" FontSize="14" IsEnabled="False">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Include?">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Tag="{Binding ID}" HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="True" Name="ckTblInclude" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding Schema}" Header="Schema"/>
<DataGridTextColumn Binding="{Binding Name}" Header="Name"/>
</DataGrid.Columns>
</DataGrid>
\u Tables
是一个列表(表格类型)
如何在
GenerateTyping
过程中执行Include?
检查?我必须将复选框模板更改为以下内容:
<CheckBox Tag="{Binding ID}" HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding Include, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Name="ckTblInclude" />
我已将复选框更改为
,在列表中添加了一个Include
属性,但仍然无法做出正确的决定,这确实起到了作用
<CheckBox Tag="{Binding ID}" HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding Include, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Name="ckTblInclude" />
Private Sub GrabTables()
Dim _Db As Database = Srv.Databases(DBName)
Dim _Tbls As TableCollection = _Db.Tables
Dim _tct As Integer = _Tbls.Count
Dim _i As Integer = 0
For i = 0 To _tct - 1
If Not _Tbls(i).IsSystemObject Then
_i += 1
_Tables.Add(New TableTyping() With {
.ID = _i,
.Name = _Tbls(i).Name,
.Schema = _Tbls(i).Schema,
.Columns = ProcessColumns(_Tbls(i).Columns),
.Include = True})
End If
Next
_TCount = _Tables.Count
End Sub