本文整理汇总了C#中System.Windows.Controls.Border.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# Border.SetBinding方法的具体用法?C# Border.SetBinding怎么用?C# Border.SetBinding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.Border
的用法示例。
在下文中一共展示了Border.SetBinding方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateWidgetControl
public FrameworkElement CreateWidgetControl(IDiagram widgetViewModel, ContextMenu contextMenu)
{
var buttonHolder = widgetViewModel as DefaultWidgetViewModel;
var brd = new Border
{
DataContext = buttonHolder,
ContextMenu = contextMenu,
BorderBrush = System.Windows.Media.Brushes.Gray,
Background = System.Windows.Media.Brushes.White
};
var ret = new Button { DataContext = buttonHolder, ContextMenu = contextMenu, Content = "New Widget" };
brd.Child = ret;
var heightBinding = new Binding("Height") { Source = buttonHolder, Mode = BindingMode.TwoWay };
var widthBinding = new Binding("Width") { Source = buttonHolder, Mode = BindingMode.TwoWay };
var xBinding = new Binding("X") { Source = buttonHolder, Mode = BindingMode.TwoWay };
var yBinding = new Binding("Y") { Source = buttonHolder, Mode = BindingMode.TwoWay };
var transformBinding = new Binding("RenderTransform") { Source = buttonHolder, Mode = BindingMode.OneWay };
brd.SetBinding(InkCanvas.LeftProperty, xBinding);
brd.SetBinding(InkCanvas.TopProperty, yBinding);
brd.SetBinding(FrameworkElement.HeightProperty, heightBinding);
brd.SetBinding(FrameworkElement.WidthProperty, widthBinding);
brd.SetBinding(UIElement.RenderTransformProperty, transformBinding);
return brd;
}
示例2: ChangeFocusBorder
/// <summary>
/// Changes the given control's border based on whether it has focus.
/// </summary>
/// <param name="sender">The target border.</param>
/// <param name="isFocussed">Indicates whether or not the control has focus.</param>
public static void ChangeFocusBorder(Border target, bool isFocussed)
{
if(target == null)
{
return;
}
if(isFocussed)
{
target.SetBinding(Border.BorderBrushProperty, _focusBorderBrushBinding);
}
else
{
target.SetBinding(Border.BorderBrushProperty, _defaultForegroundBinding);
}
}
示例3: BorderSelectionAdorner
// Be sure to call the base class constructor.
public BorderSelectionAdorner(TreeViewEx treeViewEx)
: base(treeViewEx)
{
this.treeViewEx = treeViewEx;
this.border = new Border { BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(1), Opacity = 0.5 };
Binding brushBinding = new Binding("BorderBrushSelectionRectangle");
brushBinding.Source = treeViewEx;
border.SetBinding(Border.BorderBrushProperty, brushBinding);
Binding backgroundBinding = new Binding("BackgroundSelectionRectangle");
backgroundBinding.Source = treeViewEx;
border.SetBinding(Border.BackgroundProperty, backgroundBinding);
layer = AdornerLayer.GetAdornerLayer(treeViewEx);
layer.Add(this);
}
示例4: InlineModalDecorator
/// <summary>
/// Initializes a new instance of the <see cref="InlineModalDecorator"/> class.
/// </summary>
public InlineModalDecorator()
{
_panel = new Grid();
AddVisualChild(_panel);
AddLogicalChild(_panel);
_blurrer = new Border { Visibility = Visibility.Collapsed };
_blurrer.SetBinding(StyleProperty, new Binding { Source = this, Path = new PropertyPath(BlurrerStyleProperty) });
_panel.Children.Add(_blurrer);
}
示例5: BuildWindowCore
protected override System.Runtime.InteropServices.HandleRef BuildWindowCore(System.Runtime.InteropServices.HandleRef hwndParent)
{
_wpfContentHost = new HwndSource(new HwndSourceParameters()
{
ParentWindow = hwndParent.Handle,
WindowStyle = Win32Helper.WS_CHILD | Win32Helper.WS_VISIBLE | Win32Helper.WS_CLIPSIBLINGS | Win32Helper.WS_CLIPCHILDREN,
Width = 1,
Height = 1
});
_rootPresenter = new Border() { Child = new AdornerDecorator() { Child = Content }, Focusable = true };
_rootPresenter.SetBinding(Border.BackgroundProperty, new Binding("Background") { Source = _owner });
_wpfContentHost.RootVisual = _rootPresenter;
_wpfContentHost.SizeToContent = SizeToContent.Manual;
_manager = _owner.Model.Root.Manager;
_manager.InternalAddLogicalChild(_rootPresenter);
return new HandleRef(this, _wpfContentHost.Handle);
}
示例6: GenerateGrid_Click
private void GenerateGrid_Click(object sender, RoutedEventArgs e)
{
ChristmasLightsGrid dc = (ChristmasLightsGrid) DataContext;
dc.Rows = dc.Columns;
dc.GenerateGridCommand.Execute(null);
for (int y = 0; y < dc.Rows; y++)
{
LightGrid.RowDefinitions.Add(new RowDefinition {Height = new GridLength(2)});
LightGrid.ColumnDefinitions.Add(new ColumnDefinition {Width = new GridLength(2)});
}
int i = 0;
Stopwatch stopwatch = Stopwatch.StartNew();
for (int x = 0; x < dc.Columns; x++)
{
for (int y = 0; y < dc.Rows; y++)
{
Border cell = new Border();
cell.SetBinding(Border.BackgroundProperty,
new Binding
{
Path =
new PropertyPath(
$"Lights[{i}].Lit"),
Source = dc,
Converter = new BoolToBrushConverter(),
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
IsAsync = true
});
Grid.SetColumn(cell, x);
Grid.SetRow(cell, y);
LightGrid.Children.Add(cell);
i++;
}
}
stopwatch.Stop();
TimeSpan span = new TimeSpan(stopwatch.ElapsedTicks);
Console.WriteLine($"Time taken for {dc.Columns}x{dc.Rows} grid: {span}");
}
示例7: CreerTerrain
public Grid CreerTerrain()
{
var grid = new Grid();
for (int x = 0; x < 17; x++)
grid.ColumnDefinitions.Add(new ColumnDefinition());
for (int y = 0; y < 20; y++)
grid.RowDefinitions.Add(new RowDefinition());
for (int x = 0; x < 20; x++)
for (int y = 0; y < 17; y++)
{
var childrenGrid = new Grid();
var border = new Border();
if (_plateauDeJeu.ZoneList.Exists(a => a.PositionX == x && a.PositionY == y))
{
var zone = _plateauDeJeu.ZoneList.First(a => a.PositionX == x && a.PositionY == y);
childrenGrid.DataContext = zone;
foreach (var objet in zone.ObjetList)
{
var binding = new Binding("Image");
border.SetBinding(Border.BackgroundProperty, binding);
if (objet is PacGomme)
zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\point.png", UriKind.Relative)));
if (objet is SuperPacGomme)
zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\pomme.png", UriKind.Relative)));
if (objet is Porte)
zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\porte.png", UriKind.Relative)));
}
childrenGrid.Children.Add(border);
}
else
{
border.Background = new SolidColorBrush(Colors.Red);
childrenGrid.Children.Add(border);
}
if (_plateauDeJeu.PersonnageList.Any(a => a.ZoneAbstraite.PositionX == x && a.ZoneAbstraite.PositionY == y))
{
var zone = _plateauDeJeu.ZoneList.First(a => a.PositionX == x && a.PositionY == y);
var personnage = _plateauDeJeu.PersonnageList.FirstOrDefault(a => a.ZoneAbstraite.PositionX == x && a.ZoneAbstraite.PositionY == y);
{
if (personnage is PacMan)
zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\Pacman.png", UriKind.Relative)));
if (personnage is Fantome)
{
var random = new Random();
var res = random.Next(1, 3);
switch (res)
{
case 1:
zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\Pacman-bleu.png", UriKind.Relative)));
break;
case 2:
zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\Pacman-rose.png", UriKind.Relative)));
break;
case 3:
zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\Pacman-rouge.png", UriKind.Relative)));
break;
}
}
}
}
childrenGrid.SetValue(Grid.RowProperty, x);
childrenGrid.SetValue(Grid.ColumnProperty, y);
grid.Children.Add(childrenGrid);
}
return grid;
}
示例8: TargetDataGridChanged
private static void TargetDataGridChanged(DependencyObject dependencyObject,
DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
var footersPresenter = dependencyObject as DataGridFootersPresenter;
Debug.Assert(footersPresenter != null, "footersPresenter != null");
var newGrid = dependencyPropertyChangedEventArgs.NewValue as DataGrid;
Debug.Assert(newGrid != null, "newGrid != null");
FooterData conatiner = GetFooterContainer(newGrid);
foreach (DataGridColumn column in newGrid.Columns)
{
var columnFooterContent = new TextBlock
{
TextWrapping = TextWrapping.WrapWithOverflow,
TextTrimming = TextTrimming.CharacterEllipsis,
FontWeight = FontWeights.SemiBold
};
string conent = GetFooterContent(column);
if (!string.IsNullOrWhiteSpace(conent))
{
columnFooterContent.Text = conent;
}
string columnId = GetFooterColumnId(column);
if (!string.IsNullOrWhiteSpace(columnId))
{
columnFooterContent.SetBinding(TextBlock.TextProperty,
new Binding(string.Format("[{0}]", columnId)) {Source = conatiner});
}
var border = new Border
{
BorderThickness = new Thickness(0.0f, 0.0f, 0.0f, 0.0f),
BorderBrush = new SolidColorBrush(Colors.LightGray)
};
var actualWidthBinding = new Binding("ActualWidth") {Source = column};
border.SetBinding(WidthProperty, actualWidthBinding);
border.Child = columnFooterContent;
footersPresenter.Items.Add(border);
}
}
示例9: GeneratePanel
private StackPanel GeneratePanel(object dataItem)
{
StackPanel panel = new StackPanel();
panel.Orientation = Orientation.Horizontal;
IGanttNode node = (IGanttNode)dataItem;
Binding bind = new Binding("Level");
bind.ConverterParameter = dataItem;
bind.Mode = BindingMode.OneWay;
bind.Converter = new LevelToWidthConverter();
Border b = new Border();
b.BorderThickness = new Thickness(0);
b.Background = new SolidColorBrush(Colors.Transparent);
b.SetBinding(Border.WidthProperty, bind);
bind = new Binding("Expanded");
bind.Mode = BindingMode.TwoWay;
SimpleExpander expander = new SimpleExpander();
expander.Visibility = (node.ChildNodes.Count == 0) ? Visibility.Collapsed : Visibility.Visible;
expander.IsExpandedChanged += new EventHandler(expander_IsExpandedChanged);
expander.SetBinding(SimpleExpander.IsExpandedProperty, bind);
panel.Children.Add(b);
panel.Children.Add(expander);
return panel;
}
示例10: BuildWindowCore
protected override HandleRef BuildWindowCore(HandleRef hwndParent)
{
_wpfContentHost = new HwndSource(new HwndSourceParameters()
{
ParentWindow = hwndParent.Handle,
WindowStyle =
Win32Helper.WsChild | Win32Helper.WsVisible | Win32Helper.WsClipsiblings | Win32Helper.WsClipchildren,
Width = 1,
Height = 1
});
_rootPresenter = new Border() {Child = new AdornerDecorator() {Child = Content}, Focusable = true};
_rootPresenter.SetBinding(Border.BackgroundProperty, new Binding("Background") {Source = _owner});
_wpfContentHost.RootVisual = _rootPresenter;
_wpfContentHost.SizeToContent = SizeToContent.Manual;
_manager = _owner.Model.Root.Manager;
_manager.InternalAddLogicalChild(_rootPresenter);
return new HandleRef(this, _wpfContentHost.Handle);
}
示例11: GenerateIndent
Border GenerateIndent()
{
var bind = new Binding(LevelPath);
bind.Mode = BindingMode.OneWay;
bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bind.Converter = IndentConverter;
var b = new Border();
b.BorderThickness = new Thickness(0);
b.Background = new SolidColorBrush(Colors.Transparent);
b.SetBinding(Border.WidthProperty, bind);
return b;
}
示例12: Clone
public DragGrip Clone()
{
var newItem = new DragGrip
{
Name = "Cloned" + Guid.NewGuid().ToString().Replace("-", ""),
RenderTransform =
new TranslateTransform(((TranslateTransform) RenderTransform).X,
((TranslateTransform) RenderTransform).Y),
InitialPoint = InitialPoint,
IsDragable = false,
IsToolBarItem = true,
IsSelected = false,
ContextMenuName = ContextMenuName,
};
var binding = new Binding
{
RelativeSource = new RelativeSource
{
Mode = RelativeSourceMode.FindAncestor,
AncestorType = typeof (DragGrip)
},
Path = new PropertyPath("IsSelected"),
Converter = new BoolToIntConverter(),
ConverterParameter = "2.5",
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
Mode = BindingMode.TwoWay
};
var border = new Border
{
Background = ((Border) Child).Background,
Width = ActualWidth,
Height = ActualHeight,
BorderBrush = Brushes.DeepSkyBlue,
Child = new TextBlock
{
Text = ((TextBlock) ((Border) Child).Child).Text,
FontSize = 16,
Foreground = Brushes.White,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center,
Margin = ((TextBlock) ((Border) Child).Child).Margin
}
};
border.SetBinding(Border.BorderThicknessProperty, binding);
newItem.ContextMenu = (ContextMenu)((Canvas)Parent).FindResource(ContextMenuName);
newItem.Child = border;
return newItem;
}
示例13: refresh
/// <summary>
/// Regenerate tone display
/// </summary>
private void refresh()
{
//Stop if we have the tone collection is not set
if (Tones == null)
return;
//Clear the tone container
grdTones.Children.Clear();
//Stop here if there are no tones to display
if (Tones.Count == 0)
return;
//Calculate the width of pixels that is one unit tone duration
double width = getBlockWidth();
//Add each tone
foreach (var tone in Tones)
{
//Create the tone border
var b = new Border();
//Create the textblock to hold the tone string
var t = new TextBlock();
t.Text = tone.KeyString;
//Position the tone
b.Margin = new Thickness(width * tone.StartBlock, 0, 0, 0);
//Bind the tone width
var binding = new Binding("Duration");
binding.Source = tone;
binding.Converter = new MultiplyConverter();
binding.ConverterParameter = width;
b.SetBinding(Border.WidthProperty, binding);
//Add the tone to the display
b.Child = t;
grdTones.Children.Add(b);
}
padDisplay();
}