本文整理汇总了C#中System.Windows.Controls.CheckBox.AddHandler方法的典型用法代码示例。如果您正苦于以下问题:C# CheckBox.AddHandler方法的具体用法?C# CheckBox.AddHandler怎么用?C# CheckBox.AddHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.CheckBox
的用法示例。
在下文中一共展示了CheckBox.AddHandler方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateCellContent
public override void CreateCellContent(C1FlexGrid grid, System.Windows.Controls.Border bdr, CellRange rng)
{
if (grid.Cells[rng.Row, rng.Column] is bool)
{
// it does, so create a checkbox to show/edit the value
CheckBox chk = new CheckBox();
chk.IsChecked =(bool?)grid.Cells[rng.Row, rng.Column];
chk.VerticalAlignment = VerticalAlignment.Center;
chk.HorizontalAlignment = HorizontalAlignment.Center;
ToolTipService.SetToolTip(chk, "This CheckBox represents a boolean value stored in a grid cell.");
// assign the checkbox to the cell element (a Border)
bdr.Child = chk;
// connect the checkbox so it updates the content of the grid cell
chk.Tag = grid;
chk.AddHandler(CheckBox.ClickEvent, new RoutedEventHandler(chk_Click));
}
else if (grid.Cells[rng.Row, rng.Column] is Control)
{
// add the control to the cell (if it doesn't have a parent)
Control ctl = (Control)grid.Cells[rng.Row, rng.Column];
if (ctl.Parent == null)
{
bdr.Child =(System.Windows.Controls.Control) grid.Cells[rng.Row, rng.Column];
}
}
else
{
// not a boolean, allow default behavior
base.CreateCellContent(grid, bdr, rng);
}
}
示例2: RefreshTabContent
/// <summary>
/// 具体刷新Tab内容的方法
/// </summary>
/// <param name="tab"></param>
private void RefreshTabContent(TabItem tab)
{
//logger.Debug("刷新控件ing");
if (tab.Tag == null)
return;
int index = (int)tab.Tag;
var prompts = viewModel.Prompts.Where(it => it.TabIndex == index)
.ToList();
Grid grid = new Grid();
ScrollViewer viewer = new ScrollViewer();
viewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
viewer.Content = grid;
tab.Content = viewer;
grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(10) });
grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength() });
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(20) });
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(230) });
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(220) });
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(250, GridUnitType.Star) });
StackPanel leftSP = new StackPanel();
leftSP.Margin = new Thickness(5, 0, 30, 0);
leftSP.SetValue(Grid.RowProperty, 1);
leftSP.SetValue(Grid.ColumnProperty, 1);
StackPanel middleSP = new StackPanel();
middleSP.Margin = new Thickness(30, 0, 30, 0);
middleSP.SetValue(Grid.RowProperty, 1);
middleSP.SetValue(Grid.ColumnProperty, 2);
StackPanel rightSP = new StackPanel();
rightSP.Margin = new Thickness(30, 0, 0, 0);
rightSP.SetValue(Grid.RowProperty, 1);
rightSP.SetValue(Grid.ColumnProperty, 3);
grid.Children.Add(leftSP);
grid.Children.Add(middleSP);
grid.Children.Add(rightSP);
for (int i = 0; i < prompts.Count(); i++)
{
var prompt = prompts[i];
if (prompt.ControlType == ControlType.TextBox
|| prompt.ControlType == ControlType.UnEditabledTextBox
|| prompt.ControlType == ControlType.Invisabled)
{
Label label = new Label();
label.Foreground = getBrushById(prompt.ColorIndex);
label.DataContext = prompt;
label.SetBinding(Label.ContentProperty, new Binding("Name"));
label.SetBinding(Label.VisibilityProperty, new Binding("Visible") { Converter = new PromptValueToVisibilityConverter() });
label.SetBinding(Label.ToolTipProperty, new Binding("HelpMessage"));
leftSP.Children.Add(label);
TextBox tb = new TextBox();
//tb.MouseDoubleClick += tb_MouseDoubleClick;
tb.AddHandler(UIElement.MouseEnterEvent, new RoutedEventHandler(tb_MouseLeftButtonDown), true);
tb.DataContext = prompt;
tb.SetBinding(TextBox.TextProperty, new Binding("PromptValue") { ValidatesOnExceptions = true, ValidatesOnDataErrors = true, NotifyOnValidationError = true });
tb.SetBinding(TextBox.VisibilityProperty, new Binding("Visible") { Converter = new PromptValueToVisibilityConverter() });
tb.SetBinding(TextBox.IsEnabledProperty, new Binding("IsEnabled"));
tb.SetBinding(TextBox.ToolTipProperty, new Binding("HelpMessage"));
leftSP.Children.Add(tb);
TextBlock error = new TextBlock();
error.Foreground = Brushes.Red;
error.DataContext = prompt;
error.SetBinding(TextBlock.TextProperty, new Binding("ErrorMessage"));
error.SetBinding(Label.VisibilityProperty, new Binding("ErrorMessage") { Converter = new PromptValueToVisibilityConverter() });
leftSP.Children.Add(error);
}
else if (prompt.ControlType == ControlType.CheckBox)
{
CheckBox cb = new CheckBox();
cb.Foreground = getBrushById(prompt.ColorIndex);
cb.Margin = new Thickness(0, 3, 0, 3);
cb.DataContext = prompt;
cb.AddHandler(UIElement.MouseEnterEvent, new RoutedEventHandler(tb_MouseLeftButtonDown), true);
cb.SetBinding(CheckBox.IsCheckedProperty, new Binding("PromptValue") { Converter = new PromptValueToCheckedConverter() });
cb.SetBinding(CheckBox.ContentProperty, new Binding("Name"));
cb.SetBinding(CheckBox.VisibilityProperty, new Binding("Visible") { Converter = new PromptValueToVisibilityConverter() });
cb.SetBinding(CheckBox.ToolTipProperty, new Binding("HelpMessage"));
rightSP.Children.Add(cb);
}
else if (prompt.ControlType == ControlType.ComboBox)
{
Label label = new Label();
label.Foreground = getBrushById(prompt.ColorIndex);
label.DataContext = prompt;
label.SetBinding(Label.ContentProperty, new Binding("Name"));
label.SetBinding(Label.VisibilityProperty, new Binding("Visible") { Converter = new PromptValueToVisibilityConverter() });
//.........这里部分代码省略.........