本文整理汇总了C#中System.Windows.Controls.RadioButton.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# RadioButton.SetBinding方法的具体用法?C# RadioButton.SetBinding怎么用?C# RadioButton.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.RadioButton
的用法示例。
在下文中一共展示了RadioButton.SetBinding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateContent
private void UpdateContent()
{
if (panel == null)
return;
panel.Children.Clear();
if (Value == null)
return;
var enumValues = Enum.GetValues(Value.GetType()).FilterOnBrowsableAttribute();
var converter = new EnumToBooleanConverter { EnumType = Value.GetType() };
var relativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(RadioButtonList), 1);
var descriptionConverter = new EnumDescriptionConverter();
foreach (var itemValue in enumValues )
{
var rb = new RadioButton { Content = descriptionConverter.Convert(itemValue, typeof(string), null, CultureInfo.CurrentCulture) };
// rb.IsChecked = Value.Equals(itemValue);
var isCheckedBinding = new Binding("Value")
{
Converter = converter,
ConverterParameter = itemValue,
Mode = BindingMode.TwoWay,
RelativeSource = relativeSource
};
rb.SetBinding(ToggleButton.IsCheckedProperty, isCheckedBinding);
var itemMarginBinding = new Binding("ItemMargin") { RelativeSource = relativeSource };
rb.SetBinding(MarginProperty, itemMarginBinding);
panel.Children.Add(rb);
}
}
示例2: CreateCellElement
public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
{
var radioButton = new RadioButton { Margin = new Thickness(3.0, 0.0, 3.0, 0.0) };
if (DataMemberBinding != null)
radioButton.SetBinding(ToggleButton.IsCheckedProperty, DataMemberBinding);
radioButton.Checked += RadioButtonChecked;
return radioButton;
}
示例3: OnApplyTemplate
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
True = (RadioButton)GetTemplateChild("PART_True");
True.SetBinding(RadioButton.IsCheckedProperty, new Binding { Source = this, Path = new PropertyPath(CurrentValueProperty), Mode = BindingMode.TwoWay });
True.Checked += Checked;
False = (RadioButton)GetTemplateChild("PART_False");
False.SetBinding(RadioButton.IsCheckedProperty, new Binding { Source = this, Path = new PropertyPath(CurrentValueProperty), Mode = BindingMode.TwoWay, Converter = new BooleanReverseValueConverter() });
False.Checked += Checked;
}
示例4: SetupCustomUIElements
public override void SetupCustomUIElements(dynNodeView nodeUI)
{
this.dynamoViewModel = nodeUI.ViewModel.DynamoViewModel;
//add a text box to the input grid of the control
var rbTrue = new RadioButton();
var rbFalse = new RadioButton();
rbTrue.VerticalAlignment = VerticalAlignment.Center;
rbFalse.VerticalAlignment = VerticalAlignment.Center;
//use a unique name for the button group
//so other instances of this element don't get confused
string groupName = Guid.NewGuid().ToString();
rbTrue.GroupName = groupName;
rbFalse.GroupName = groupName;
rbTrue.Content = "True";
rbTrue.Padding = new Thickness(0,0,12,0);
rbFalse.Content = "False";
rbFalse.Padding = new Thickness(0);
var wp = new WrapPanel()
{
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch,
Margin = new Thickness(10,5,10,0),
Orientation = Orientation.Horizontal
};
wp.Children.Add(rbTrue);
wp.Children.Add(rbFalse);
nodeUI.inputGrid.Children.Add(wp);
//rbFalse.IsChecked = true;
rbTrue.Checked += OnRadioButtonClicked;
rbFalse.Checked += OnRadioButtonClicked;
rbFalse.DataContext = this;
rbTrue.DataContext = this;
var rbTrueBinding = new Binding("Value") { Mode = BindingMode.TwoWay, };
rbTrue.SetBinding(ToggleButton.IsCheckedProperty, rbTrueBinding);
var rbFalseBinding = new Binding("Value")
{
Mode = BindingMode.TwoWay,
Converter = new InverseBoolDisplay()
};
rbFalse.SetBinding(ToggleButton.IsCheckedProperty, rbFalseBinding);
}
示例5: SexEditor
public SexEditor(WorkFrame frame)
: base(frame)
{
StackPanel panel = new StackPanel();
panel.Orientation = Orientation.Horizontal;
RadioButton girl = new RadioButton();
girl.GroupName = "Sex";
girl.Content = "女";
panel.Children.Add(girl);
RadioButton boy = new RadioButton();
boy.DataContext = this;
boy.GroupName = "Sex";
boy.Content = "男";
panel.Children.Add(boy);
var binding = new Binding("Value");
binding.Mode = BindingMode.TwoWay;
boy.SetBinding(RadioButton.IsCheckedProperty, binding);
Content = panel;
}
示例6: BoolEditor
public BoolEditor(WorkFrame frame)
: base(frame)
{
StackPanel panel = new StackPanel();
panel.Orientation = Orientation.Horizontal;
RadioButton yes = new RadioButton();
yes.DataContext = this;
yes.GroupName = "Bool";
yes.Content = "是";
panel.Children.Add(yes);
RadioButton no = new RadioButton();
no.GroupName = "Bool";
no.Content = "否";
panel.Children.Add(no);
var binding = new Binding("Value");
binding.Mode = BindingMode.TwoWay;
yes.SetBinding(RadioButton.IsCheckedProperty, binding);
Content = panel;
}
示例7: CreateEnumField
private static ModelPropertyUiInfo CreateEnumField(Grid parent,
Type enumType,
DisplayPropertyInfo property,
String bindingPath,
Style style,
int row,
int column)
{
ModelPropertyUiInfo elememtsInfo = new ModelPropertyUiInfo(property);
// create label
Label labelElement = CreateLabel(property, row, column);
parent.Children.Add(labelElement);
elememtsInfo.Label = labelElement;
// create inputs
var panel = new WrapPanel()
{
Orientation = Orientation.Horizontal,
Margin = new Thickness(4),
};
Grid.SetRow(panel, row);
Grid.SetColumn(panel, checked(column + 1));
parent.Children.Add(panel);
elememtsInfo.Content = panel;
if (!enumType.IsEnum) return elememtsInfo;
Array enumValues = Enum.GetValues(enumType);
foreach (var item in enumValues)
{
RadioButton control = new RadioButton
{
Name = "radioButton" + property.PropertyName + "_" + item.ToString(),
// TODO: Localization for enum values
Content = item.ToString(),
GroupName = property.PropertyName,
Margin = new Thickness(4),
};
if (style != null)
{
control.Style = style;
}
control.SetBinding(ToggleButton.IsCheckedProperty,
ModelUiCreatorHelper.CreateBinding(property, bindingPath, new EnumToBooleanConverter(), item.ToString()));
if (property.IsReadOnly)
{
control.IsEnabled = false;
}
panel.Children.Add(control);
}
return elememtsInfo;
}
示例8: CreateLabel
/// <summary>
/// Creates the label control.
/// </summary>
/// <param name="pi">The property item.</param>
/// <returns>
/// An element.
/// </returns>
private FrameworkElement CreateLabel(PropertyItem pi)
{
FrameworkElement propertyLabel = null;
if (pi.IsOptional)
{
var cb = new CheckBox
{
Content = pi.DisplayName,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(5, 0, 0, 0)
};
cb.SetBinding(
ToggleButton.IsCheckedProperty,
pi.OptionalDescriptor != null ? new Binding(pi.OptionalDescriptor.Name) : new Binding(pi.Descriptor.Name) { Converter = NullToBoolConverter });
var g = new Grid();
g.Children.Add(cb);
propertyLabel = g;
}
if (pi.IsEnabledByRadioButton)
{
var rb = new RadioButton
{
Content = pi.DisplayName,
GroupName = pi.RadioDescriptor.Name,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(5, 0, 0, 0)
};
var converter = new EnumToBooleanConverter();
converter.EnumType = pi.RadioDescriptor.PropertyType;
rb.SetBinding(
RadioButton.IsCheckedProperty,
new Binding(pi.RadioDescriptor.Name) { Converter = converter, ConverterParameter = pi.RadioValue });
var g = new Grid();
g.Children.Add(rb);
propertyLabel = g;
}
if (propertyLabel == null)
{
propertyLabel = new Label
{
Content = pi.DisplayName,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Thickness(0, 4, 0, 0)
};
}
propertyLabel.Margin = new Thickness(0, 0, 4, 0);
return propertyLabel;
}
示例9: UpdateContent
/// <summary>
/// Updates the content.
/// </summary>
private void UpdateContent()
{
if (this.panel == null)
{
return;
}
this.panel.Children.Clear();
var enumType = this.EnumType;
if (enumType != null)
{
var ult = Nullable.GetUnderlyingType(enumType);
if (ult != null)
{
enumType = ult;
}
}
if (this.Value != null)
{
enumType = this.Value.GetType();
}
if (enumType == null || !typeof(Enum).IsAssignableFrom(enumType))
{
return;
}
var enumValues = Enum.GetValues(enumType).FilterOnBrowsableAttribute();
var converter = new EnumToBooleanConverter { EnumType = enumType };
foreach (var itemValue in enumValues)
{
var rb = new RadioButton
{
Content =
this.DescriptionConverter.Convert(
itemValue, typeof(string), null, CultureInfo.CurrentCulture),
Padding = this.ItemPadding
};
var isCheckedBinding = new Binding("Value")
{
Converter = converter, ConverterParameter = itemValue, Source = this, Mode = BindingMode.TwoWay
};
rb.SetBinding(ToggleButton.IsCheckedProperty, isCheckedBinding);
rb.SetBinding(MarginProperty, new Binding("ItemMargin") { Source = this });
this.panel.Children.Add(rb);
}
}
示例10: OnItemSourceChanged
protected static void OnItemSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is CRMMenuControl)
{
var topMenuControl = (CRMMenuControl)d;
if (topMenuControl.ItemSource == null)
return;
if (topMenuControl.rootMenuPanel.Children.Count > 0)
{
topMenuControl.rootMenuPanel.Children.Clear();
}
var topMenuGroupName = Guid.NewGuid().ToString();
var topMenuEnumerator = topMenuControl.ItemSource.GetEnumerator();
while (topMenuEnumerator.MoveNext())
{
var topMenuButton = new RadioButton()
{
Style = Application.Current.Resources["topMenuButtonStyle"] as Style,
DataContext = topMenuEnumerator.Current,
GroupName = topMenuGroupName,
Margin = new Thickness(0, 0, 1, 0),
Padding = new Thickness(10, 5, 10, 1),
HorizontalContentAlignment = HorizontalAlignment.Center,
VerticalContentAlignment = VerticalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center
};
topMenuButton.SetBinding(RadioButton.ContentProperty, new System.Windows.Data.Binding()
{
Converter = new TopMenuContentValueConverter(),
ConverterParameter = topMenuControl.DisplayMemberPath
});
topMenuButton.AddHandler(UIElement.MouseLeftButtonUpEvent, new MouseButtonEventHandler(topMenuControl.MenuItemButtonClick), true);
topMenuControl.rootMenuPanel.Children.Add(topMenuButton);
}
}
}
示例11: GetLogControl
//.........这里部分代码省略.........
Grid.SetRow(lableLogQuality, 0);
lableLogName.HorizontalAlignment = HorizontalAlignment.Stretch;
lableLogName.VerticalAlignment = VerticalAlignment.Stretch;
gridLog.Children.Add(lableLogQuality);
for (int m = 0; m < columnCount; m++)
{
var kpi = logs[0].Kpis[m];
var lableLog = new TextBlock
{
Text = kpi.KpiName + (kpi.KpiName.Contains("FTP") ? "" : "(%)"),
FontSize = 12,
FontWeight = FontWeights.Bold,
MaxWidth = 80,
TextWrapping = TextWrapping.Wrap
};
lableLog.SetValue(ToolTipService.ToolTipProperty,
kpi.KpiName + (kpi.KpiName.Contains("FTP") ? "" : "(%)"));
Grid.SetColumn(lableLog, m + margin);
lableLog.VerticalAlignment = VerticalAlignment.Center;
lableLog.HorizontalAlignment = HorizontalAlignment.Center;
Grid.SetRow(lableLog, 0);
lableLog.SetValue(Canvas.ZIndexProperty, 10);
gridLog.Children.Add(lableLog);
}
var countLog = 0;
for (int i = 0; i < logGroup.Count(); i++)
{
countLog++;
StackPanel stackPanelLog = new StackPanel() {Orientation = Orientation.Horizontal};
var rb = new RadioButton() { Tag = logGroup[i], VerticalAlignment = VerticalAlignment.Center, GroupName = groupName+logGroup[i].LogServertype };
rb.SetBinding(RadioButton.IsCheckedProperty,
new Binding() { Source = rb.Tag, Path = new PropertyPath("IsSelected"), Mode = BindingMode.TwoWay });
stackPanelLog.Children.Add(rb);
var logtxt = new TextBlock
{
FontSize = 12,
FontWeight = FontWeights.Bold,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Left,
Margin = new Thickness(20, 0, 0, 0)
};
var run = new Run
{
Text = logGroup[i].LogName,
};
logtxt.Inlines.Add(run);
var br = new LineBreak();
logtxt.Inlines.Add(br);
var dataType = new Underline();
dataType.Inlines.Add(new Run
{
Text = logGroup[i].LogServertype + "(打点图)"
});
logtxt.Inlines.Add(dataType);
stackPanelLog.Children.Add(logtxt);
var lableNameLog1 = new Border
{
Child = stackPanelLog,
Margin = new Thickness(1, 0, 1, 1),
Cursor = Cursors.Hand
示例12: BuildGUIConfiguration
protected override System.Windows.FrameworkElement BuildGUIConfiguration()
{
RadioButton r1 = new RadioButton()
{
Content = "Row",
GroupName = "DeleteMode",
};
r1.SetBinding(RadioButton.IsCheckedProperty, new Binding("DeleteRow"));
RadioButton r2 = new RadioButton()
{
Content = "Column",
GroupName = "DeleteMode",
};
r2.SetBinding(RadioButton.IsCheckedProperty, new Binding("DeleteColumn"));
StackPanel panel = new StackPanel();
panel.Children.Add(r1);
panel.Children.Add(r2);
return panel;
}
示例13: SetupControl
private void SetupControl(FoundOps.Core.Models.CoreEntities.Repeat schedule)
{
var monthlyFrequencyDetailsStackPanel = new StackPanel();
if (schedule == null || schedule.AvailableMonthlyFrequencyDetailTypes == null)
{
this.Content = null;
this.InvalidateArrange();
return;
}
foreach (var monthlyFrequencyDetail in schedule.AvailableMonthlyFrequencyDetailTypes)
{
var monthlyFrequencyDetailRadioButton = new RadioButton { GroupName = "RepeatOn" };
monthlyFrequencyDetailRadioButton.SetBinding(ContentControl.ContentProperty,
new Binding("StartDate")
{
Source = schedule,
Converter =
new MonthlyFrequencyDetailToStringConverter(
monthlyFrequencyDetail)
});
monthlyFrequencyDetailRadioButton.SetBinding(ToggleButton.IsCheckedProperty,
new Binding("FrequencyDetailAsMonthlyFrequencyDetail")
{
Source = schedule,
Converter =
new MonthlyFrequencyDetailIsCheckedConverter(
monthlyFrequencyDetail)
});
var detail = monthlyFrequencyDetail;
monthlyFrequencyDetailRadioButton.Checked += (o, args) =>
{
Value.FrequencyDetailAsMonthlyFrequencyDetail = detail;
};
monthlyFrequencyDetailsStackPanel.Children.Add(monthlyFrequencyDetailRadioButton);
}
this.Content = monthlyFrequencyDetailsStackPanel;
this.InvalidateArrange();
}
示例14: 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() });
//.........这里部分代码省略.........
示例15: CreatePluginViews
void CreatePluginViews()
{
var views =
PluginsManager.Current.Plugins
.Where(p => p.StreamViews != null)
.SelectMany(p => p.StreamViews)
.ToList();
foreach (var view in views)
{
// Create radio button to switch to this view
var button = new RadioButton
{
GroupName = "StreamViewToggle",
Content = view.Header,
Style = (Style)FindResource("SwitcherToggleIconRadio")
};
IStreamViewPlugin view1 = view;
button.Click += delegate
{
SettingsManager.ClientSettings.AppConfiguration.DefaultView = view1.Header;
SettingsManager.Save();
view1.SwitchToView();
};
button.DataContext = view;
button.SetBinding(IsEnabledProperty, "CanSwitchToView");
StreamViewsRadioButtons.Children.Add(button);
}
}