本文整理汇总了C#中System.Windows.Controls.ContentPresenter.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# ContentPresenter.SetBinding方法的具体用法?C# ContentPresenter.SetBinding怎么用?C# ContentPresenter.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ContentPresenter
的用法示例。
在下文中一共展示了ContentPresenter.SetBinding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PopupButton
public PopupButton()
{
var content = new ContentPresenter();
content.SetBinding(ContentPresenter.ContentProperty, new Binding("PopupContent") { Source = this });
var border = new Border()
{
CornerRadius = new CornerRadius(5),
BorderThickness = new Thickness(1),
Child = content
};
border.SetResourceReference(Border.BackgroundProperty, "BaseWindowBackgroundBrush");
border.SetResourceReference(Border.BorderBrushProperty, "WindowBorderBrush");
_popup = new Popup()
{
AllowsTransparency = true,
StaysOpen = false,
Placement = PlacementMode.Bottom,
PlacementTarget = this,
DataContext = this,
Child = border,
};
_popup.SetBinding(Popup.IsOpenProperty, "IsChecked");
_popup.SetBinding(Popup.WidthProperty, "Width");
SetBinding(PopupButton.IsHitTestVisibleProperty, new Binding("IsOpen") { Source = _popup, Mode = BindingMode.OneWay, Converter = new InverseBooleanConverter() });
}
示例2: 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;
}
示例3: GenerateEditingElementCore
protected override FrameworkElement GenerateEditingElementCore()
{
var control = new ContentPresenter
{
ContentTemplate = this.EditingTemplate
};
control.SetBinding(ContentPresenter.ContentProperty, this.Binding);
return control;
}
示例4: RealizeContent
public void RealizeContent()
{
if (_contentPresenter != null)
{
return;
// throw new InvalidOperationException("Already realized!"); // probably want to not throw in the future, but just no-op out?
}
Debug("RealizeContent");
_contentPresenter = new ContentPresenter
{
HorizontalAlignment = HorizontalContentAlignment,
VerticalAlignment = VerticalContentAlignment,
Margin = Padding,
IsHitTestVisible = false,
};
_contentPresenter.Loaded += OnContentPresenterLoaded;
_contentPresenter.Unloaded += OnContentPresenterUnloaded;
_contentPresenter.SetBinding(
ContentPresenter.ContentTemplateProperty,
new Binding("ContentTemplate") { BindsDirectlyToSource = true, Source = this });
_contentPresenter.SetBinding(
ContentPresenter.ContentProperty,
new Binding("Content") { BindsDirectlyToSource = true, Source = this });
_contentPanel.Children.Add(_contentPresenter);
_contentPanel.Visibility = Visibility.Visible; // ? is this one needed ?
}
示例5: BindContentPresenterContent
public void BindContentPresenterContent ()
{
ContentPresenter presenter = new ContentPresenter ();
presenter.SetBinding (ContentPresenter.ContentProperty, new Binding ("Opacity"));
CustomControl c = new CustomControl { Content = presenter };
CreateAsyncTest (c,
() => {
c.DataContext = new Data { Opacity = 1.0 };
}, () => {
Assert.AreEqual (1.0, presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#1");
Assert.AreEqual (1.0, presenter.Content, "#2");
c.DataContext = new Data { Opacity = 0.0 };
}, () => {
Assert.AreEqual (0.0, presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#3");
Assert.AreEqual (0.0, presenter.Content, "#4");
}
);
}
示例6: 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);
}
示例7: DialogBase
public DialogBase()
{
// You might ask yourself why this is happening...
//
// It's all because WPF apparently has a bug where if you use the Template property on Window to customize the
// visual tree of its content (i.e., put the button tray / progressive disclosure / footnote stuff in), everything
// works great *except* you don't get focus visuals for any of the controls.
//
// So to get around that, we don't mess with the template of the window itself, but instead:
// 1) Programmatically create a ContentPresenter and set it as the content of the Window (dialog)
// 2) Change the default content property to be "MainContent" (so the xaml for DialogBase derivations looks "normal")
// 3) Bind the content presenter to the MainContent property (and the template to MainContentTemplate)
//
// Viola! Plus the dialogs are now individually customizable via MainContentTemplate.
var content = new ContentPresenter() { Focusable = false, Content = new SelfWrapper(this) };
content.SetBinding(ContentPresenter.ContentTemplateProperty, new Binding { Source = this, Path = new PropertyPath(MainContentTemplateProperty) });
this.Content = content;
this.buttons = new ObservableCollection<Button>();
this.Loaded += OnLoaded;
}
示例8: UnmaskHiddenContent
private void UnmaskHiddenContent()
{
if (_contentGrid == null)
{
#if DEBUG
throw new InvalidOperationException("Content grid must be present.");
#endif
return;
}
if (_contentPresenter != null)
{
#if DEBUG
throw new InvalidOperationException("Unmasking cannot happen twice.");
#endif
return;
}
//_hasUnmaskedContent = true;
var contentBinding = new Binding( "Content") { BindsDirectlyToSource = true, Source = this };
var templateBinding = new Binding("ContentTemplate") { BindsDirectlyToSource = true, Source = this };
_contentPresenter = new ContentPresenter
{
HorizontalAlignment = HorizontalContentAlignment,
VerticalAlignment = VerticalContentAlignment,
Margin = Padding,
IsHitTestVisible = false,
};
_contentPresenter.Loaded += OnContentPresenterLoaded;
_contentPresenter.Unloaded += OnContentPresenterUnloaded;
_contentPresenter.SetBinding(ContentPresenter.ContentTemplateProperty, templateBinding);
_contentPresenter.SetBinding(ContentPresenter.ContentProperty, contentBinding);
_contentGrid.Children.Add(_contentPresenter);
_contentGrid.Visibility = Visibility.Visible;
_okToShowAfter = DateTime.Now + MinimumLoadingTime;
_timeoutAfter = DateTime.Now + TimeoutSpan; // probably don't need this one
if (_timeoutTimer == null)
{
_timeoutTimer = new DispatcherTimer();
_timeoutTimer.Interval = TimeoutSpan;
_timeoutTimer.Tick += OnTimeoutTimerTick;
}
_timeoutTimer.Start();
}
示例9: ListBox_MouseEnter
//static void lb_MouseDown(object sender, MouseButtonEventArgs e)
//{
// Adorner ad = sender as Adorner;
// FrameworkElement fe = ad.AdornedElement as FrameworkElement;
// fe.RaiseEvent(e);
//}
private static void ListBox_MouseEnter(object sender, MouseEventArgs e)
{
// Check that we are hovering on a ListBoxItem
FrameworkElement lb = sender as FrameworkElement;
MouseOverArdornerInfo ct = GetAttachedAdorner(lb);
if (ct == null)
return;
if (_Adorners.ContainsKey(lb))
return;
AdornerLayer layer = AdornerLayer.GetAdornerLayer(lb);
ContentPresenter cp = new ContentPresenter();
cp.ContentTemplate = ct.Template;
Binding b = new Binding();
b.Path = new PropertyPath("DataContext");
b.Source = lb;
b.Mode = BindingMode.OneWay;
cp.SetBinding(ContentPresenter.ContentProperty, b);
UIElementAdorner uea = new UIElementAdorner(lb) { Child = cp };
//uea.OffsetLeft = ct.VerticalOffset;
//uea.OffsetTop = ct.HorizontalOffset;
layer.Add(uea);
_Adorners.Add(lb, uea);
//uea.MouseLeave += new MouseEventHandler(uea_MouseLeave);
//uea.MouseDown += lb_MouseDown;
//uea.PreviewMouseDown += lb_MouseDown;
//uea.PreviewMouseLeftButtonUp += new MouseButtonEventHandler(lb_MouseDown);
//uea.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(lb_MouseDown);
//uea.MouseLeftButtonUp += new MouseButtonEventHandler(lb_MouseDown);
//uea.MouseLeftButtonDown += new MouseButtonEventHandler(lb_MouseDown);
//uea.PreviewMouseRightButtonUp += new MouseButtonEventHandler(uea_PreviewMouseRightButtonDown);
//uea.PreviewMouseRightButtonDown += new MouseButtonEventHandler(lb_MouseDown);
//uea.MouseRightButtonUp += new MouseButtonEventHandler(lb_MouseDown);
//uea.MouseRightButtonDown += new MouseButtonEventHandler(lb_MouseDown);
}
示例10: PageClone
public PageClone()
{
content = new ContentPresenter();
content.SetBinding(ContentPresenter.ContentProperty, new Binding("Content") { Source = this });
AddVisualChild(content);
}
示例11: UnmaskHiddenContent
private void UnmaskHiddenContent()
{
// LIPEx
// if (_contentGrid == null)
// {
//#if DEBUG
// throw new InvalidOperationException("Content grid must be present.");
//#endif
// return;
// }
// LPIEx
// if (_contentPresenter != null)
// {
//#if DEBUG
// throw new InvalidOperationException("Unmasking cannot happen twice.");
//#endif
// return;
// }
//_hasUnmaskedContent = true;
var contentBinding = new Binding("Content") { BindsDirectlyToSource = true, Source = this };
var templateBinding = new Binding("ContentTemplate") { BindsDirectlyToSource = true, Source = this };
_contentPresenter = new ContentPresenter
{
HorizontalAlignment = HorizontalContentAlignment,
VerticalAlignment = VerticalContentAlignment,
Margin = Padding,
IsHitTestVisible = false,
};
_contentPresenter.Loaded += OnContentPresenterLoaded;
_contentPresenter.Unloaded += OnContentPresenterUnloaded;
_contentPresenter.SetBinding(ContentPresenter.ContentTemplateProperty, templateBinding);
_contentPresenter.SetBinding(ContentPresenter.ContentProperty, contentBinding);
_contentGrid.Children.Add(_contentPresenter);
_contentGrid.Visibility = Visibility.Visible;
_okToShowAfter = DateTime.Now + MinimumLoadingTime;
}
示例12: GetCurrentContent
private ContentPresenter GetCurrentContent()
{
var item = _tabControl.SelectedItem;
if (item == null) return null;
var tabItem = _tabControl.ItemContainerGenerator.ContainerFromItem(item);
if (tabItem == null) return null;
var cachedContent = TabContent.GetInternalCachedContent(tabItem);
if (cachedContent == null)
{
cachedContent = new ContentPresenter
{
DataContext = item,
ContentTemplate = TabContent.GetTemplate(_tabControl),
ContentTemplateSelector = TabContent.GetTemplateSelector(_tabControl)
};
cachedContent.SetBinding(ContentPresenter.ContentProperty, new Binding());
TabContent.SetInternalCachedContent(tabItem, cachedContent);
}
return cachedContent;
}
示例13: TemplatedAdorner
public TemplatedAdorner(UIElement adornedElement, AdornerLayer adornerLayer)
: base(adornedElement)
{
_adornerLayer = adornerLayer;
_contentPresenter = new ContentPresenter();
//绑定内容
var contentBinding = new Binding
{
Mode = BindingMode.TwoWay,
Source = adornedElement,
Path = new PropertyPath(MaskAttach.DataContextProperty)
};
_contentPresenter.SetBinding(ContentPresenter.ContentProperty, contentBinding);
//绑定模板
var contentTemplateBinding = new Binding
{
Mode = BindingMode.TwoWay,
Source = adornedElement,
Path = new PropertyPath(MaskAttach.TemplateProperty)
};
_contentPresenter.SetBinding(ContentPresenter.ContentTemplateProperty, contentTemplateBinding);
//当控件发生大小变化的时候需要强制刷新,不过加这句效率会有影响
//AdornedElement.LayoutUpdated += AdornedElementLayoutUpdated;
//加入层中
_adornerLayer.Add(this);
//加入可视树是为了防止点击穿过
AddVisualChild(_contentPresenter);
}
示例14: SetFileTabDefinition
public void SetFileTabDefinition(FileTabDefinition fileTabDefinition)
{
this.DataContext = fileTabDefinition;
if (fileTabDefinition.IsSeparator)
{
this.Content = new Separator();
this.IsEnabled = false;
}
else
{
this.SetBinding(TabItem.HeaderProperty, new Binding { Source = fileTabDefinition, Path = new PropertyPath(FileTabDefinition.HeaderProperty) });
var presenter = new ContentPresenter();
presenter.SetBinding(ContentPresenter.ContentTemplateProperty, new Binding { Source = fileTabDefinition, Path = new PropertyPath(FileTabDefinition.ContentTemplateProperty) });
this.Content = presenter;
this.command = fileTabDefinition.Command as RoutedCommand;
if (fileTabDefinition.Command != null)
{
fileTabDefinition.Command.CanExecuteChanged += OnCommandCanExecuteChanged;
this.IsEnabled = this.command == null ? fileTabDefinition.Command.CanExecute(fileTabDefinition.CommandParameter) : this.command.CanExecute(fileTabDefinition.CommandParameter, fileTabDefinition.CommandTarget);
}
}
}
示例15: DataContextTest_DataContextUpdatesAsync
public void DataContextTest_DataContextUpdatesAsync ()
{
var presenter = new ContentPresenter ();
presenter.SetBinding (ContentPresenter.DataContextProperty, new Binding ());
Assert.IsInstanceOfType<BindingExpression> (presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#1");
presenter.Content = new object ();
Assert.IsInstanceOfType<BindingExpression> (presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#2");
TestPanel.Children.Add (presenter);
Assert.IsInstanceOfType<BindingExpression> (presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#3");
Enqueue (() => {
Assert.AreSame (presenter.Content, presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#4");
});
EnqueueTestComplete ();
}