本文整理汇总了C#中System.Windows.Controls.ContentPresenter.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# ContentPresenter.SetValue方法的具体用法?C# ContentPresenter.SetValue怎么用?C# ContentPresenter.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ContentPresenter
的用法示例。
在下文中一共展示了ContentPresenter.SetValue方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ThemedWindow
public ThemedWindow()
{
this.ShouldBeThemed();
WindowStyle = WindowStyle.None;
ResizeMode = ResizeMode.CanResizeWithGrip;
Background = Brushes.Transparent;
AllowsTransparency = true;
WindowStartupLocation = WindowStartupLocation.CenterOwner;
ShowInTaskbar = false;
Grid host = new Grid();
//Header
host.RowDefinitions.Add(new RowDefinition
{
Height = GridLength.Auto
});
//Body
host.RowDefinitions.Add(new RowDefinition());
FrameworkElement header = BuildHeaderArea();
header.SetValue(Grid.RowProperty, 0);
host.Children.Add(header);
ContentPresenter contentPresenter = new ContentPresenter();
contentPresenter.SetValue(Grid.RowProperty, 1);
contentPresenter.SetBinding(ContentPresenter.ContentProperty, new Binding
{
Mode = BindingMode.OneWay,
RelativeSource = new RelativeSource
{
Mode = RelativeSourceMode.FindAncestor,
AncestorType = typeof(ThemedWindow)
},
Path = new PropertyPath("Content")
});
contentPresenter.Resources = Resources;
host.Children.Add(contentPresenter);
host.SetResourceReference(BackgroundProperty, EnvironmentColors.ToolWindowBackgroundBrushKey);
Border hostContainer = new Border
{
Child = host,
//Margin = new Thickness(1, 1, 5, 5),
BorderThickness = new Thickness(1)
};
hostContainer.SetResourceReference(BorderBrushProperty, EnvironmentColors.MainWindowActiveDefaultBorderBrushKey);
//hostContainer.Effect = new DropShadowEffect
//{
// Direction = -75,
// ShadowDepth = 2,
// BlurRadius = 2,
// Color = Colors.Azure
//};
base.Content = hostContainer;
}
示例2: DragContentAdorner
public DragContentAdorner(UIElement adornedElement, object draggedData, DataTemplate dataTemplate, Point offset)
: base(adornedElement)
{
_contentPresenter = new ContentPresenter {
Content = draggedData,
ContentTemplate = dataTemplate,
Opacity = 0.7
};
_translate = new TranslateTransform { X = 0, Y = 0 };
_contentPresenter.RenderTransform = _translate;
_offset = offset;
Host.Children.Add(_contentPresenter);
_contentPresenter.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Left);
_contentPresenter.SetValue(VerticalAlignmentProperty, VerticalAlignment.Top);
}
示例3: BeginTransition
protected internal override void BeginTransition(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
{
Storyboard oldStoryboard = OldContentStoryboard;
Storyboard newStoryboard = NewContentStoryboard;
if (oldStoryboard != null || newStoryboard != null)
{
oldContent.Style = OldContentStyle;
newContent.Style = NewContentStyle;
// Flag to determine when both storyboards are done
bool done = oldStoryboard == null || newStoryboard == null;
if (oldStoryboard != null)
{
oldStoryboard = oldStoryboard.Clone();
oldContent.SetValue(OldContentStoryboardProperty, oldStoryboard);
oldStoryboard.Completed += delegate
{
if (done)
EndTransition(transitionElement, oldContent, newContent);
done = true;
};
oldStoryboard.Begin(oldContent, true);
}
if (newStoryboard != null)
{
newStoryboard = newStoryboard.Clone();
newContent.SetValue(NewContentStoryboardProperty, newStoryboard);
newStoryboard.Completed += delegate
{
if (done)
EndTransition(transitionElement, oldContent, newContent);
done = true;
};
newStoryboard.Begin(newContent, true);
}
}
else
{
EndTransition(transitionElement, oldContent, newContent);
}
}
示例4: CreateTickMark
/// <summary>
///
/// </summary>
/// <param name="start"></param>
/// <param name="end"></param>
/// <returns></returns>
FrameworkElement CreateTickMark(Point start, Point end, TickLocation location)
{
// If no template was specified, use the default
if (TickTemplate == null)
{
System.Windows.Shapes.Line ln = new System.Windows.Shapes.Line();
ln.Stroke = new SolidColorBrush(Colors.Black);
ln.StrokeThickness = 1.0;
ln.X1 = start.X;
ln.Y1 = start.Y;
ln.X2 = end.X;
ln.Y2 = end.Y;
return ln;
}
else
{
ContentPresenter cp = new ContentPresenter();
//cp.Content = "a";
cp.ContentTemplate = TickTemplate;
if (location == TickLocation.Top)
{
cp.SetValue(Canvas.TopProperty, start.Y - cp.ActualHeight);
cp.SetValue(Canvas.LeftProperty, start.X - (cp.ActualWidth / 2));
}
else
{
cp.SetValue(Canvas.TopProperty, end.Y);
cp.SetValue(Canvas.LeftProperty, start.X - (cp.ActualWidth / 2));
}
return cp;
}
}
示例5: AddTickmark
private void AddTickmark(double position)
{
ContentPresenter c = new ContentPresenter();
c.SetValue(PositionProperty, position);
c.SetBinding(ContentPresenter.ContentTemplateProperty, new System.Windows.Data.Binding()
{
Source = this,
BindsDirectlyToSource = true,
Path = new PropertyPath("TickMarkTemplate")
});
Children.Add(c);
}
示例6: SetIsCenter
private static void SetIsCenter(ContentPresenter element, bool value)
{
element.SetValue(IsCentersCenterPropertyKey, value);
}
示例7: CreateDragAdorner
private static void CreateDragAdorner(DropInfo dropInfo)
{
var template = GetDragAdornerTemplate(m_DragInfo.VisualSource);
var templateSelector = GetDragAdornerTemplateSelector(m_DragInfo.VisualSource);
UIElement adornment = null;
var useDefaultDragAdorner = GetUseDefaultDragAdorner(m_DragInfo.VisualSource);
var useVisualSourceItemSizeForDragAdorner = GetUseVisualSourceItemSizeForDragAdorner(m_DragInfo.VisualSource);
if (template == null && templateSelector == null && useDefaultDragAdorner) {
var bs = CaptureScreen(m_DragInfo.VisualSourceItem, m_DragInfo.VisualSourceFlowDirection);
if (bs != null) {
var factory = new FrameworkElementFactory(typeof(Image));
factory.SetValue(Image.SourceProperty, bs);
factory.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);
factory.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality);
factory.SetValue(FrameworkElement.WidthProperty, bs.Width);
factory.SetValue(FrameworkElement.HeightProperty, bs.Height);
factory.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Left);
factory.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Top);
template = new DataTemplate { VisualTree = factory };
}
}
if (template != null || templateSelector != null) {
if (m_DragInfo.Data is IEnumerable && !(m_DragInfo.Data is string)) {
if (!useDefaultDragAdorner && ((IEnumerable)m_DragInfo.Data).Cast<object>().Count() <= 10) {
var itemsControl = new ItemsControl();
itemsControl.ItemsSource = (IEnumerable)m_DragInfo.Data;
itemsControl.ItemTemplate = template;
itemsControl.ItemTemplateSelector = templateSelector;
if (useVisualSourceItemSizeForDragAdorner)
{
var bounds = VisualTreeHelper.GetDescendantBounds(m_DragInfo.VisualSourceItem);
itemsControl.SetValue(FrameworkElement.MinWidthProperty, bounds.Width);
}
// The ItemsControl doesn't display unless we create a grid to contain it.
// Not quite sure why we need this...
var grid = new Grid();
grid.Children.Add(itemsControl);
adornment = grid;
}
} else {
var contentPresenter = new ContentPresenter();
contentPresenter.Content = m_DragInfo.Data;
contentPresenter.ContentTemplate = template;
contentPresenter.ContentTemplateSelector = templateSelector;
if (useVisualSourceItemSizeForDragAdorner)
{
var bounds = VisualTreeHelper.GetDescendantBounds(m_DragInfo.VisualSourceItem);
contentPresenter.SetValue(FrameworkElement.MinWidthProperty, bounds.Width);
contentPresenter.SetValue(FrameworkElement.MinHeightProperty, bounds.Height);
}
adornment = contentPresenter;
}
}
if (adornment != null) {
if (useDefaultDragAdorner) {
adornment.Opacity = GetDefaultDragAdornerOpacity(m_DragInfo.VisualSource);
}
var rootElement = RootElementFinder.FindRoot(dropInfo.VisualTarget ?? m_DragInfo.VisualSource);
DragAdorner = new DragAdorner(rootElement, adornment);
}
}
示例8: Render
private void Render()
{
ColumnDefinitions.Clear();
Children.Clear();
if (ItemsSource == null) return;
var i = 0;
foreach (var item in ItemsSource)
{
var valueProperty = item.GetType().GetProperty(ValueMemberPath);
var value = valueProperty != null ? (int)valueProperty.GetValue(item, null) : 1;
var column = new ColumnDefinition {Width = new GridLength(value, GridUnitType.Star)};
ColumnDefinitions.Add(column);
var bar = new ContentPresenter {ContentTemplate = ItemTemplate, Content = item};
Children.Add(bar);
bar.SetValue(ColumnProperty, i);
i++;
}
}
示例9: CreateTick
FrameworkElement CreateTick(Point start, Point end)
{
if (TickTemplate == null) {
Line ln = new Line();
ln.SetBinding(Line.StrokeProperty, new System.Windows.Data.Binding("Foreground"));
ln.StrokeThickness = 1.0;
ln.X1 = start.X;
ln.Y1 = start.Y;
ln.X2 = end.X;
ln.Y2 = end.Y;
return ln;
} else {
ContentPresenter cp = new ContentPresenter();
cp.Content = "a";
cp.ContentTemplate = TickTemplate;
cp.SetValue(Canvas.TopProperty, (IsHorizontal ? start.Y : start.Y - cp.ActualHeight / 2 ));
cp.SetValue(Canvas.LeftProperty, (IsHorizontal ? start.X - cp.ActualWidth / 2 : start.X));
return cp;
}
//return null;
}
示例10: SetRefreshTriggerBinding
public static void SetRefreshTriggerBinding(ContentPresenter element, bool value)
{
element.SetValue(RefreshTriggerBindingProperty, value);
}