本文整理汇总了C#中System.Windows.Controls.Slider.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# Slider.SetBinding方法的具体用法?C# Slider.SetBinding怎么用?C# Slider.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.Slider
的用法示例。
在下文中一共展示了Slider.SetBinding方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateView
public FrameworkElement CreateView(PropertyInfo property)
{
var rangeAttr = property.GetCustomAttributes(typeof(RangeAttribute),
false).FirstOrDefault() as RangeAttribute;
if (rangeAttr != null)
{
var inputControl = new Grid();
inputControl.ColumnDefinitions.Add(new ColumnDefinition
{
Width = new GridLength(1, GridUnitType.Star)
});
inputControl.ColumnDefinitions.Add(new ColumnDefinition
{
Width = new GridLength(0, GridUnitType.Auto)
});
var slider = new Slider();
slider.Minimum = Convert.ToDouble(rangeAttr.Minimum);
slider.Maximum = Convert.ToDouble(rangeAttr.Maximum);
var binding = new Binding(property.Name);
binding.Mode = BindingMode.TwoWay;
slider.SetBinding(Slider.ValueProperty, binding);
inputControl.Children.Add(slider);
var tb = new TextBlock();
slider.ValueChanged += (s, e) =>
{
tb.Text = e.NewValue.ToString(".00");
};
inputControl.Children.Add(tb);
Grid.SetColumn(tb, 1);
return inputControl;
}
else
{
return new StringConfigControl().CreateView(property);
}
}
示例2: OnApplyTemplate
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
ColorGradientsListBox = GetTemplateChild("ColorGradientsListBox") as ListBox;
if (ColorGradientsListBox != null)
{
loadColorGradientsListBox();
ColorGradientsListBox.SelectionChanged += new SelectionChangedEventHandler(onListBoxSelectionChanged);
}
CancelButton = GetTemplateChild("CancelButton") as Button;
if(CancelButton != null)
CancelButton.Click += new RoutedEventHandler(CancelButton_Click);
OKButton = GetTemplateChild("OKButton") as Button;
if(OKButton != null)
OKButton.Click += new RoutedEventHandler(OkButton_Click);
IntensitySlider = GetTemplateChild("IntensitySlider") as Slider;
if (IntensitySlider != null)
{
IntensitySlider.SetBinding(Slider.ValueProperty, new Binding()
{
Mode = BindingMode.TwoWay,
Source = DataContext,
Path = new PropertyPath("Intensity")
});
}
ResolutionSlider = GetTemplateChild("ResolutionSlider") as Slider;
if (ResolutionSlider != null)
{
ResolutionSlider.SetBinding(Slider.ValueProperty, new Binding()
{
Mode = BindingMode.TwoWay,
Source = DataContext,
Path = new PropertyPath("Resolution")
});
}
}
示例3: build_gui
private void build_gui()
{
this.DataContext = spectrum;
Rectangle rect1 = new Rectangle();
rect1.Width = 70;
rect1.Height = 70;
Binding bind_brush = new Binding("SpectrumBrush");
rect1.SetBinding(Rectangle.FillProperty, bind_brush);
StackPanel sp = new StackPanel();
StackPanel sp1 = this.tb_slider("R", "Red:");
StackPanel sp2 = this.tb_slider("G", "Green:");
StackPanel sp3 = this.tb_slider("B", "Blue:");
sp.Children.Add(sp1);
sp.Children.Add(sp2);
sp.Children.Add(sp3);
Slider rainbow_slider = new Slider();
rainbow_slider.Width = 300;
rainbow_slider.Minimum = 0.0;
rainbow_slider.Maximum = 1.0;
rainbow_slider.Background = this.spectrum.rainbow_brush(new Point(0.0, 0.5), new Point(1.0, 0.5));
Binding bind_rainbow = new Binding("RainbowValue");
rainbow_slider.SetBinding(Slider.ValueProperty, bind_rainbow);
StackPanel sp_color = new StackPanel();
sp_color.Orientation = Orientation.Horizontal;
sp_color.Height = 80;
sp_color.Children.Add(rect1);
sp_color.Children.Add(sp);
StackPanel all = new StackPanel();
all.Children.Add(sp_color);
all.Children.Add(rainbow_slider);
all.Height = 120;
all.Width = 300;
this.Content = all;
}
示例4: DoNewControl2
private void DoNewControl2(object obj)
{
var element = new Slider { Width = 100 };
element.SetBinding(Slider.ValueProperty, new Binding("InputValue") { Mode = BindingMode.TwoWay });
element.SetBinding(Slider.IsEnabledProperty, new Binding("IsAuthenticated") { Source = AuthVM });
SubView = element;
}
示例5: Add
public static void Add(Grid grid, string label, Binding value, int row, double minimum, double maximum, string labelStyle, string inputStyle, int startColumn)
{
int column = startColumn;
if (label != "")
{
TextBlock labelElement = new TextBlock();
labelElement.Style = App.Instance.Resources[labelStyle] as Style;
labelElement.SetResourceReference(TextBlock.TextProperty, label);
labelElement.VerticalAlignment = VerticalAlignment.Center;
labelElement.Margin = new Thickness(column > 0 ? 5 : 0, 0, 10, 0);
grid.Children.Add(labelElement);
Grid.SetColumn(labelElement, column);
Grid.SetRow(labelElement, row);
column += 1;
}
System.Windows.Controls.Slider inputElement = new System.Windows.Controls.Slider();
inputElement.Orientation = Orientation.Horizontal;
inputElement.Minimum = minimum;
inputElement.Maximum = maximum;
inputElement.HorizontalAlignment = HorizontalAlignment.Stretch;
inputElement.Margin = new Thickness(column > 0 ? 5 : 0, 0, 0, 5);
if (inputStyle != "")
{
Style s = App.Instance.Resources[inputStyle] as Style;
if (s.TargetType == typeof(System.Windows.Controls.Slider))
inputElement.Style = s;
}
inputElement.SetBinding(System.Windows.Controls.Slider.ValueProperty, value);
grid.Children.Add(inputElement);
Grid.SetColumn(inputElement, column);
Grid.SetRow(inputElement, row);
}
示例6: CreateSliderControl
/// <summary>
/// Creates the slider control.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>
/// The control.
/// </returns>
protected virtual FrameworkElement CreateSliderControl(PropertyItem property)
{
var g = new Grid();
g.ColumnDefinitions.Add(
new System.Windows.Controls.ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
g.ColumnDefinitions.Add(
new System.Windows.Controls.ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
var s = new Slider
{
Minimum = property.SliderMinimum,
Maximum = property.SliderMaximum,
SmallChange = property.SliderSmallChange,
LargeChange = property.SliderLargeChange,
TickFrequency = property.SliderTickFrequency,
IsSnapToTickEnabled = property.SliderSnapToTicks
};
s.SetBinding(RangeBase.ValueProperty, property.CreateBinding());
g.Children.Add(s);
var trigger = property.AutoUpdateText ? UpdateSourceTrigger.PropertyChanged : UpdateSourceTrigger.Default;
var c = new TextBoxEx { IsReadOnly = property.Descriptor.IsReadOnly };
var formatString = property.FormatString;
if (formatString != null && !formatString.StartsWith("{"))
{
formatString = "{0:" + formatString + "}";
}
var binding = property.CreateBinding();
binding.StringFormat = formatString;
binding.UpdateSourceTrigger = trigger;
c.SetBinding(TextBox.TextProperty, binding);
Grid.SetColumn(c, 1);
g.Children.Add(c);
return g;
}
示例7: VideoDashboard
public VideoDashboard()
{
cardCount = 0;
InitializeComponent();
mainWPanel = new WrapPanel();
mainWPanel.Width = 1050;
rightSPanel = new StackPanel();
rightSPanel.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
rightSPanel.Orientation = Orientation.Vertical;
rightSPanel.Width = 180;
bottom = new GroupBox();
bottom.Header = "Controls";
bottom.Content = rightSPanel;
cards = new List<Card>();
addCard = new Button { Content = "Add Card", Margin = new Thickness(3) };
playAll = new Button { Content = "Play All", Margin = new Thickness(3) };
plusTenMS = new Button { Content = "+10 milliseconds", Margin = new Thickness(10,3,10,3) };
minusTenMS = new Button { Content = "-10 milliseconds", Margin = new Thickness(10,3,10,3) };
speedRatioSlider = new Slider { Orientation = Orientation.Vertical, Height = 75, Margin = new Thickness(72, 5, 72, 5), Value = 0 };
speedRatioSlider.Maximum = 1.2;
Binding binding_sRatioTooltip = new Binding("Value");
binding_sRatioTooltip.Source = speedRatioSlider;
speedRatioSlider.SetBinding(Slider.ToolTipProperty, binding_sRatioTooltip);
mainStack.CanVerticallyScroll = true;
mainStack.Children.Add(mainWPanel);
mainStack.Children.Add(bottom);
addCard.Click += addCard_Click;
playAll.Click += playAll_Click;
plusTenMS.Click += (s, e) =>
{
foreach (var p in players)
{
p.Pause();
}
playAll.Content = "Play All";
foreach (var c in cards)
{
c.advanceMediaPos(10);
}
};
minusTenMS.Click += (s, e) =>
{
foreach (var p in players)
{
p.Pause();
}
playAll.Content = "Play All";
foreach (var c in cards)
{
c.advanceMediaPos(-10);
}
};
rightSPanel.Children.Add(addCard);
rightSPanel.Children.Add(playAll);
rightSPanel.Children.Add(new GroupBox { Header = "Speed Ratio", Content = speedRatioSlider });
rightSPanel.Children.Add(plusTenMS);
rightSPanel.Children.Add(minusTenMS);
players = new List<MediaUriElement>();
closeButtons = new List<CustomButton>();
}
示例8: tb_slider
private StackPanel tb_slider(string property_name, string label, float max)
{
TextBlock tb_key = new TextBlock();
tb_key.Text = label;
tb_key.Height = 20;
tb_key.Width = 65;
tb_key.TextAlignment = TextAlignment.Right;
Slider slider = new Slider();
slider.Minimum = 0.0;
slider.Maximum = max;
slider.Width = 150;
Binding bind_slider = new Binding(property_name);
slider.SetBinding(Slider.ValueProperty, bind_slider);
TextBox tbox_key = new TextBox();
tbox_key.Width = 60;
tbox_key.Height = 20;
tbox_key.Foreground = Brushes.White;
tbox_key.CaretBrush = Brushes.White;
Binding bind_tbox_key = new Binding(property_name);
tbox_key.SetBinding(TextBox.TextProperty, bind_tbox_key);
StackPanel sp_key = new StackPanel();
sp_key.Orientation = Orientation.Horizontal;
sp_key.Height = 25;
sp_key.Children.Add(tb_key);
sp_key.Children.Add(slider);
sp_key.Children.Add(tbox_key);
return sp_key;
}
示例9: PopulateSettings
/// <summary>
/// Populates the settings panel with the settings of a given plugin.
/// </summary>
/// <param name="plugin">The plugin whose settings to display</param>
private void PopulateSettings(Plugin plugin)
{
SettingsGrid.RowDefinitions.Clear();
SettingsGrid.Children.Clear();
for (int i = 0; i < plugin.Settings.Count; i++)
{
Setting s = plugin.Settings[i];
// add row
SettingsGrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
// create label
TextBlock tb = new TextBlock()
{
Text = plugin.T(s.ID),
Margin = new Thickness(5, 5, 10, 5),
VerticalAlignment = VerticalAlignment.Center
};
tb.SetBinding(TextBlock.VisibilityProperty, new Binding("IsVisible")
{
Source = s,
Mode = BindingMode.OneWay,
Converter = new BooleanToVisibilityConverter()
});
Grid.SetRow(tb, i);
Grid.SetColumn(tb, 0);
SettingsGrid.Children.Add(tb);
FrameworkElement control = null;
// create control
if (s.Type == typeof(Boolean))
{
// checkbox
control = new CheckBox() { Height = 15 };
control.SetBinding(CheckBox.IsCheckedProperty, new Binding("Value")
{
Source = s,
Mode = BindingMode.TwoWay
});
}
else if (s.Type == typeof(Color))
{
// color selector
control = new ColorPicker()
{
ShowAvailableColors = false,
ShowStandardColors = true,
Width = 50,
};
if (s.PossibleValues != null)
{
ColorConverter converter = new ColorConverter();
((ColorPicker)control).AvailableColors.Clear();
foreach (Color c in s.PossibleValues)
{
System.Windows.Media.Color color = (System.Windows.Media.Color)converter.Convert(c, null, null, null);
((ColorPicker)control).AvailableColors.Add(new ColorItem(color, c.Name));
}
}
control.SetBinding(ColorPicker.SelectedColorProperty, new Binding("Value")
{
Source = s,
Mode = BindingMode.TwoWay,
Converter = new ColorConverter()
});
}
else if (s.PossibleValues != null)
{
// dropdown
control = new ComboBox();
foreach (Object val in s.PossibleValues)
{
try
{
String content = val.ToString();
if (s.Type == typeof(String))
content = plugin.T(val.ToString());
((ComboBox)control).Items.Add(new ComboBoxItem
{
Content = content,
Name = val.ToString()
});
}
catch (Exception exc)
{
U.L(LogLevel.Warning, "PLUGIN", "Could not add combobox item in plugin settings: " + exc.Message);
}
}
((ComboBox)control).SelectedValuePath = "Name";
control.SetBinding(ComboBox.SelectedValueProperty, new Binding("Value")
{
Source = s,
//.........这里部分代码省略.........
示例10: OnApplyTemplate
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_dgTrendPens = GetTemplateChild("dgTrendPens") as DataGrid;
if (_dgTrendPens != null)
{
UpdateDgPensColumnsVisibility();
}
_gTrendPresenters = (Grid) GetTemplateChild("gTrendPresenters");
if (_gTrendPresenters != null)
{
_gTrendPresenters.MouseLeftButtonDown += GTrendPresentersMouseLeftButtonDown;
_gTrendPresenters.MouseLeftButtonUp += GTrendPresentersMouseLeftButtonUp;
_gTrendPresenters.MouseMove += GTrendPresentersMouseMove;
}
_gVerticalAxes = (Grid)GetTemplateChild("gVerticalAxes");
_cVerticalAxes = (Canvas)GetTemplateChild("cVerticalAxes");
if (_cVerticalAxes != null)
{
_cVerticalAxes.SizeChanged += CVerticalAxesSizeChanged;
}
_cHorizontalAxes = (Canvas)GetTemplateChild("cHorizontalAxes");
if (_cHorizontalAxes != null)
{
_cHorizontalAxes.SizeChanged += CHorizontalAxesSizeChanged;
}
_spHorisontalAxes = (StackPanel)GetTemplateChild("spHorisontalAxes");
#region Slider
_slSlider = GetTemplateChild("slSlider") as Slider;
if (_slSlider != null)
{
var sliderBinding = new Binding("CursorPosition") { Source = this, Mode = BindingMode.TwoWay };
_slSlider.SetBinding(RangeBase.ValueProperty, sliderBinding);
}
_cdSliderOffset = (ColumnDefinition)GetTemplateChild("cdSliderOffset");
_gSlider = (Grid)GetTemplateChild("gSlider");
if (_gSlider != null)
_gSlider.SizeChanged += GSliderSizeChanged;
_cSlider = (Canvas)GetTemplateChild("cSlider");
if (_cSlider != null)
{
var presentersVisibilityBinding = new Binding("ShowCursorPresenters") { Source = this, Converter = new BooleanToVisibilityConverter() };
_cSlider.SetBinding(VisibilityProperty, presentersVisibilityBinding);
_cSlider.SizeChanged += CSliderSizeChanged;
}
_spSlider = (Panel)GetTemplateChild("spSlider");
UpdateSliderVisibility();
#endregion
#region SetPeriod
_popupPeriod = GetTemplateChild("popupPeriod") as Popup;
_tspSetPeriod = GetTemplateChild("tspSetPeriod") as TimeSpanPicker;
if (_popupPeriod != null && _tspSetPeriod != null)
{
_popupPeriod.Opened += PopupPeriodOpened;
_tspSetPeriod.KeyUp += TspSetPeriodKeyUp;
var bSetPeriod = GetTemplateChild("bSetPeriod") as Button;
if (bSetPeriod != null)
bSetPeriod.Click += BSetPeriodClick;
}
#endregion
#region SetTime
_popupTime = GetTemplateChild("popupTime") as Popup;
_dtpSetTime = GetTemplateChild("dtpSetTime") as DateTimePicker;
if (_popupTime != null && _dtpSetTime != null)
{
_popupTime.Opened += PopupTimeOpened;
_dtpSetTime.KeyUp += DtpSetTimeKeyUp;
var bSetTime = GetTemplateChild("bSetTime") as Button;
if (bSetTime != null)
{
bSetTime.Click += BSetTimeClick;
}
}
#endregion
}