本文整理汇总了C#中System.Windows.Controls.ContentControl.Arrange方法的典型用法代码示例。如果您正苦于以下问题:C# ContentControl.Arrange方法的具体用法?C# ContentControl.Arrange怎么用?C# ContentControl.Arrange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ContentControl
的用法示例。
在下文中一共展示了ContentControl.Arrange方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNewMessagesNotificationOverlay
public static ImageSource GetNewMessagesNotificationOverlay(Window window, DataTemplate template, int count = 0)
{
if (window == null)
return null;
var presentation = PresentationSource.FromVisual(window);
if (presentation == null)
return null;
Matrix m = presentation.CompositionTarget.TransformToDevice;
double dx = m.M11;
double dy = m.M22;
double iconWidth = 16.0 * dx;
double iconHeight = 16.0 * dy;
string countText = count.ToString();
RenderTargetBitmap bmp = new RenderTargetBitmap((int) iconWidth, (int) iconHeight, 96, 96, PixelFormats.Default);
ContentControl root = new ContentControl
{
ContentTemplate = template,
Content = count > 99 ? "…" : countText
};
root.Arrange(new Rect(0, 0, iconWidth, iconHeight));
bmp.Render(root);
return bmp;
}
示例2: OnPropertyChanged
private static void OnPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
var taskbarItemInfo = (TaskbarItemInfo) dependencyObject;
object content = GetContent(taskbarItemInfo);
DataTemplate template = GetTemplate(taskbarItemInfo);
if (template == null || content == null)
{
taskbarItemInfo.Overlay = null;
return;
}
const int ICON_WIDTH = 32;
const int ICON_HEIGHT = 32;
var bmp =
new RenderTargetBitmap(ICON_WIDTH, ICON_HEIGHT, 96, 96, PixelFormats.Default);
var root = new ContentControl
{
ContentTemplate = template,
Content = content
};
root.Arrange(new Rect(0, 0, ICON_WIDTH, ICON_HEIGHT));
bmp.Render(root);
taskbarItemInfo.Overlay = bmp;
}
示例3: PageBuilder
public PageBuilder(double width, double height, int marginsLeft, int marginsTop, int marginsRight, int marginsBottom, ContentControl frame)
{
_page = new PageContent();
_fixedPage = new FixedPage {Background = Brushes.White, Width = width, Height = height};
_repeater = new Repeater();
var repeatContainer = new Grid {Margin = new Thickness(marginsLeft, marginsTop, marginsRight, marginsBottom)};
repeatContainer.Children.Add(_repeater);
frame.SetValue(FixedPage.LeftProperty, 0.00);
frame.SetValue(FixedPage.TopProperty, 0.00);
frame.SetValue(FrameworkElement.WidthProperty, _fixedPage.Width);
frame.SetValue(FrameworkElement.HeightProperty, _fixedPage.Height);
_fixedPage.Children.Add(frame);
((IAddChild)_page).AddChild(_fixedPage);
frame.Content = repeatContainer;
frame.Measure(new Size(width, height));
frame.Arrange(new Rect(0, 0, width, height));
_repeater.Width = repeatContainer.ActualWidth;
_repeater.Height = repeatContainer.ActualHeight;
}
示例4: RenderVector
/// <summary>
/// Renders the vector icon with the specified resource key, as an image of the specified size, and returns an URI for tile icons.
/// </summary>
/// <remarks>
/// The key is for a ControlTemplate, it's the easiest way to store a path in resources.
/// </remarks>
private static Uri RenderVector( string templateKey, double size )
{
size = Math.Round( size );
string fileName = string.Format( "Shared/ShellContent/{0}_{1}.png", templateKey, size );
var control = new ContentControl();
control.Template = (ControlTemplate) Application.Current.Resources[templateKey];
control.Measure( new Size( size, size ) );
control.Arrange( new Rect( 0, 0, size, size ) );
var bitmap = new WriteableBitmap( (int) size, (int) size );
bitmap.Render( control, null );
bitmap.Invalidate();
using ( var store = IsolatedStorageFile.GetUserStoreForApplication() )
{
if ( store.FileExists( fileName ) )
{
store.DeleteFile( fileName );
}
using ( var stream = store.CreateFile( fileName ) )
{
new PngWriter( stream, bitmap ).Write();
}
}
return new Uri( "isostore:/" + fileName, UriKind.Absolute );
}
示例5: OnTaskbarOverlayPropertyChanged
/// <summary>
/// Called when the task bar overlay property is changed.
/// </summary>
/// <param name="dependencyObject">The dependency object.</param>
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
private static void OnTaskbarOverlayPropertyChanged(
DependencyObject dependencyObject,
DependencyPropertyChangedEventArgs e)
{
Window window = (Window)dependencyObject;
if ((window.TaskbarOverlay == null) && (window.TaskbarOverlayTemplate == null))
{
window.GetTaskbarItemInfoSafely().Overlay = null;
}
else if ((window.TaskbarOverlay != null) && (window.TaskbarOverlay is ImageSource) && (window.TaskbarOverlayTemplate == null))
{
window.GetTaskbarItemInfoSafely().Overlay = (ImageSource)window.TaskbarOverlay;
}
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(
OVERLAY_ICON_WIDTH,
OVERLAY_ICON_HEIGHT,
96,
96,
PixelFormats.Default);
ContentControl contentControl = new ContentControl()
{
Content = window.TaskbarOverlay,
ContentTemplate = window.TaskbarOverlayTemplate
};
contentControl.Arrange(new Rect(0, 0, OVERLAY_ICON_WIDTH, OVERLAY_ICON_HEIGHT));
renderTargetBitmap.Render(contentControl);
window.GetTaskbarItemInfoSafely().Overlay = renderTargetBitmap;
}