这里提出类似于我的问题的问题,但我没有在那里找到解决方案.
我的问题:如何将不同数据(比如Lists)绑定到不同行中每个ComboBox的"DataGridComboBoxColumn".这是我试过的代码
XAML:
<Grid>
<DataGrid x:Name="dg_TimeTable" AutoGenerateColumns="False" Margin="0,0,0,97" ColumnWidth="*">
<DataGrid.Columns>
<DataGridTextColumn IsReadOnly="True" Binding="{Binding CLASS}" Header="CLASS" />
<DataGridComboBoxColumn Header="PERIOD" x:Name="gPeriods" SelectedValueBinding="{Binding PERIOD, Mode=TwoWay}" DisplayMemberPath="{Binding PERIOD}" />
<DataGridComboBoxColumn Header="TEACHERS" x:Name="gTeachers" SelectedValueBinding="{Binding TEACHER, Mode=TwoWay}" DisplayMemberPath="{Binding TEACHER}" />
<DataGridComboBoxColumn Header="SUBJECTS" x:Name="gSubjects" SelectedValueBinding="{Binding SUBJECT, Mode=TwoWay}" DisplayMemberPath="{Binding SUBJECT}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
Run Code Online (Sandbox Code Playgroud)
的.cs
using System.Collections.ObjectModel; // For ObservableCollection
public partial class MainWindow : Window
{
ObservableCollection<string> listTeachersSix = null;
ObservableCollection<string> listTeachersSeven = null;
ObservableCollection<string> listTeachersEight = null;
ObservableCollection<string> listTeachersNine = null;
ObservableCollection<string> listTeachersTen = null; …Run Code Online (Sandbox Code Playgroud) 我搜索了更改我们使用的ListView的标题颜色:
private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Pink, e.Bounds);
e.DrawText();
}
Run Code Online (Sandbox Code Playgroud)
我们使用相同的事件来更改ListView的标题样式:
private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
using (StringFormat sf = new StringFormat())
{
sf.Alignment = StringAlignment.Center;
e.DrawBackground();
using (Font headerFont =
new Font("Microsoft Sans Serif", 9, FontStyle.Bold)) //Font size!!!!
{
e.Graphics.DrawString(e.Header.Text, headerFont,
Brushes.Black, e.Bounds, sf);
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我的问题是我想要改变标题颜色和标题样式.所以我这样写:
private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Pink, e.Bounds);
e.DrawText();
using (StringFormat sf = new StringFormat())
{
sf.Alignment = StringAlignment.Center;
e.DrawBackground();
using (Font headerFont =
new Font("Microsoft …Run Code Online (Sandbox Code Playgroud) 我正在研究 WPF 应用程序。我在 DataGrid 中有数据,我必须打印其中存在的所有数据。我试过这样...
publicMainWindow()
{
InitializeComponent();
DataTabledt = newDataTable();
dt.Columns.Add("S.No");
dt.Columns.Add("Name");
dt.Columns.Add("Father's Name");
dt.Columns.Add("D-O-B");
dt.Columns.Add("Qualification");
dt.Columns.Add("Gender");
dt.Columns.Add("SSC %");
dt.Columns.Add("+2 %");
dt.Columns.Add("Graduation %");
dt.Columns.Add("Work Experience");
dt.Columns.Add("Company");
object[] rowValues = {"01","Gopi","Ravi","31","Degree","M", "88","85", "80","2 Years","Blah Blah"};
dt.Rows.Add(rowValues);
dt.AcceptChanges();
myGrid.DataContext = dt.DefaultView;
}
privatevoidPrint_Click(object sender, RoutedEventArgs e)
{
PrintDialogprintDlg = newPrintDialog();
if ((bool)printDlg.ShowDialog().GetValueOrDefault())
{
Sizepagesize = newSize(printDlg.PrintableAreaWidth,printDlg.PrintableAreaHeight);
myGrid.Measure(pagesize);
myGrid.Arrange(newRect(5, 5, pagesize.Width, pagesize.Height));
printDlg.PrintVisual(myGrid, "Personal Information");
}
}
Run Code Online (Sandbox Code Playgroud)
但就我而言,它不是打印工作经验和公司专栏。如何打印所有字段。请帮帮我
编辑:我认为使用 FlowDocument,但假设我有 50 行我不能使用 FlowDocument。在这种情况下我如何打印。