本文整理汇总了C#中System.Windows.Controls.TextBlock.SetCurrentValue方法的典型用法代码示例。如果您正苦于以下问题:C# TextBlock.SetCurrentValue方法的具体用法?C# TextBlock.SetCurrentValue怎么用?C# TextBlock.SetCurrentValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.TextBlock
的用法示例。
在下文中一共展示了TextBlock.SetCurrentValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateControls
private void GenerateControls() {
var settings = _viewModel.Settings;
var properties = settings.GetType().GetProperties();
var groups = new Dictionary<string, Dictionary<TextBlock, Control>>();
Control firstControl = null;
foreach (var property in properties) {
var type = property.PropertyType;
var propertyPath = property.Name;
var genericType = type.IsGenericType ? type.GetGenericTypeDefinition() : null;
Control control = null;
DependencyProperty bindProperty = null;
if (genericType == typeof(SettingSingleSelection<>)) {
if (typeof(INovaromaService).IsAssignableFrom(type.GetGenericArguments().First()))
control = new SingleSelectionUserControl();
else
control = new SingleSelectComboBox();
bindProperty = DataContextProperty;
_lateBindables.Add((ILateBindable)property.GetValue(settings));
}
else if (genericType == typeof(SettingMultiSelection<>)) {
control = new MultiSelectionUserControl();
bindProperty = DataContextProperty;
_lateBindables.Add((ILateBindable)property.GetValue(settings));
}
else if (type == typeof (DirectorySelection)) {
control = new DirectorySelectUserControl();
bindProperty = DirectorySelectUserControl.TextProperty;
propertyPath += ".Path";
}
else if (!property.CanWrite) continue;
else if (type == typeof(string)) {
control = new TextBox();
bindProperty = TextBox.TextProperty;
}
else if (type.IsNumericType()) {
control = new NumericUpDown();
bindProperty = NumericUpDown.ValueProperty;
}
else if (type == typeof (bool)
|| (genericType != null && genericType == typeof(Nullable<>) && genericType.GenericTypeArguments[0] == typeof(bool))) {
control = new ToggleSwitch {Language = Language};
bindProperty = ToggleSwitch.IsCheckedProperty;
}
if (control != null && bindProperty != null) {
if (firstControl == null) firstControl = control;
var displayAttr = property.GetAttribute<DisplayAttribute>();
string displayValue;
string description;
string groupName;
if (displayAttr != null) {
displayValue = displayAttr.GetName() ?? property.Name;
description = displayAttr.GetDescription() ?? string.Empty;
groupName = displayAttr.GetGroupName() ?? string.Empty;
}
else {
displayValue = property.Name;
description = string.Empty;
groupName = string.Empty;
}
var textBlock = new TextBlock();
textBlock.VerticalAlignment = VerticalAlignment.Center;
textBlock.Margin = new Thickness(10);
textBlock.Text = displayValue;
if (!string.IsNullOrEmpty(description))
textBlock.ToolTip = description;
textBlock.SetCurrentValue(Grid.ColumnProperty, 0);
control.Margin = new Thickness(10);
control.SetCurrentValue(Grid.ColumnProperty, 1);
var binding = new Binding();
binding.Source = settings;
binding.Path = new PropertyPath(propertyPath);
binding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit;
var bindingExpression = BindingOperations.SetBinding(control, bindProperty, binding);
_bindings.Add(bindingExpression);
if (groups.ContainsKey(groupName))
groups[groupName].Add(textBlock, control);
else
groups.Add(groupName, new Dictionary<TextBlock, Control> {{textBlock, control}});
}
}
foreach (var group in groups) {
var tabItem = new TabItem();
if (groups.Count > 1)
tabItem.Header = string.IsNullOrEmpty(group.Key) ? Novaroma.Properties.Resources.Main : group.Key;
ControlsTabControl.Items.Add(tabItem);
var scrollViewer = new ScrollViewer();
tabItem.Content = scrollViewer;
var grid = new Grid();
grid.HorizontalAlignment = HorizontalAlignment.Stretch;
grid.VerticalAlignment = VerticalAlignment.Stretch;
//.........这里部分代码省略.........