本文整理汇总了C#中System.Windows.Controls.Canvas.FindName方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.FindName方法的具体用法?C# Canvas.FindName怎么用?C# Canvas.FindName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.Canvas
的用法示例。
在下文中一共展示了Canvas.FindName方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Marker
public Marker(string resourceName)
{
// Initialize from XAML and get references to child elements
_root = XamlReader.Load(Utility.GetXamlResource(resourceName)) as Canvas;
_background = _root.FindName("Background") as Rectangle;
_border = _root.FindName("Border") as Rectangle;
_pulse = _root.FindName("Pulse") as Storyboard; // May fail
Content = _root;
}
示例2: Swoosher
public Swoosher()
{
System.IO.Stream s = this.GetType().Assembly.GetManifestResourceStream( "Next2Friends.Swoosher.Swoosher.xaml" );
root = (Canvas)this.InitializeFromXaml( new System.IO.StreamReader( s ).ReadToEnd() );
timer = (Storyboard)root.Resources.FindName( "timer" );
timer.Completed += OnTick;
loading = (Loading)root.FindName( "loading" );
photoCanvas = (Canvas)root.FindName( "photoCanvas" );
backButton = (Arrow)root.FindName( "backButton" );
forwardButton = (Arrow)root.FindName( "forwardButton" );
fullscreenButton = (Arrow)root.FindName( "fullscreenButton" );
windowedButton = (Arrow)root.FindName( "windowedButton" );
physicsButton = (Arrow)root.FindName( "physicsButton" );
Loaded += OnLoaded;
}
示例3: SortNavigator
public SortNavigator(Canvas pAssembly)
{
_assemblyCanvas = pAssembly;
_speed = 0; // no animation by default.
_moveTimer = _assemblyCanvas.FindName("ScrollTimer") as Storyboard;
_thumHolder = _assemblyCanvas.FindName("ThumHolder") as Canvas;
_holderClip = _assemblyCanvas.FindName("HolderClip") as Canvas;
_btnLeft = _assemblyCanvas.FindName("BtnLeft") as Canvas;
_btnRight = _assemblyCanvas.FindName("BtnRight") as Canvas;
_topNaviLeft = _assemblyCanvas.FindName("TopNaviLeft") as Image;
_topNaviMiddle = _assemblyCanvas.FindName("TopNaviMiddle") as Image;
_topNaviRight = _assemblyCanvas.FindName("TopNaviRight") as Image;
_btnLeftImage = _assemblyCanvas.FindName("BtnLeftImage") as Image;
_btnRightImage = _assemblyCanvas.FindName("BtnRightImage") as Image;
_dividorA = _assemblyCanvas.FindName("DividorA") as Image;
_dividorB = _assemblyCanvas.FindName("DividorB") as Image;
_indexDivider = _assemblyCanvas.FindName("IndexDivider") as TextBlock;
_indexText1 = _assemblyCanvas.FindName("IndexText1") as TextBlock;
_indexText2 = _assemblyCanvas.FindName("IndexText2") as TextBlock;
_btnLeft.Cursor = Cursors.Hand;
_btnRight.Cursor = Cursors.Hand;
// Regist hover event
_btnLeft.MouseEnter += new MouseEventHandler(_btnLeft_MouseEnter);
_btnLeft.MouseLeave += new EventHandler(_btnLeft_MouseLeave);
_btnRight.MouseEnter += new MouseEventHandler(_btnRight_MouseEnter);
_btnRight.MouseLeave += new EventHandler(_btnRight_MouseLeave);
// Regist click event
_btnLeft.MouseLeftButtonDown += new MouseEventHandler(_btnLeft_MouseLeftButtonDown);
_btnLeft.MouseLeftButtonUp += new MouseEventHandler(_btnLeft_MouseLeftButtonUp);
_btnRight.MouseLeftButtonDown += new MouseEventHandler(_btnRight_MouseLeftButtonDown);
_btnRight.MouseLeftButtonUp += new MouseEventHandler(_btnRight_MouseLeftButtonUp);
// download font
_fontDownloader = new Downloader();
_fontDownloader.DownloadFailed += new ErrorEventHandler(_fontDownloader_DownloadFailed);
_fontDownloader.Completed += new EventHandler(_fontDownloader_Completed);
Uri fontUri = new Uri("Assets/Font/FuturaStd-Heavy.otf", UriKind.RelativeOrAbsolute);
_fontDownloader.Open("GET", fontUri);
_fontDownloader.Send();
}
示例4: ChildNameScope
public void ChildNameScope ()
{
Canvas b = new Canvas ();
Canvas c = (Canvas)XamlReader.Load (@"
<Canvas xmlns=""http://schemas.microsoft.com/client/2007"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Border>
<Path x:Name=""foo"" Data=""F1 M 10,10 20,20 10,20"" Stroke=""Red""/>
</Border>
</Canvas>");
Assert.IsNotNull (c.FindName ("foo"));
b.Children.Add (c);
Assert.IsNull (b.FindName ("foo"));
Assert.IsNotNull (c.FindName ("foo"));
}
示例5: VisualTypes
public void VisualTypes ()
{
Canvas c = (Canvas)XamlReader.Load (@"
<Canvas
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" >
<Border x:Name=""border"" />
</Canvas>
");
// just for sanity's sake
Assert.IsNotNull (c.FindName("border"), "0");
// Clear the children list and check if that clears the name
c.Children.Clear();
Assert.IsNull (c.FindName("border"), "1");
// try again, this time remove the border and then add it back again
c = (Canvas)XamlReader.Load (@"
<Canvas
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" >
<Border x:Name=""border"" />
</Canvas>
");
Border b = (Border)c.FindName("border");
c.Children.Remove (b);
c.Children.Add (b);
Assert.IsNotNull (c.FindName("border"), "2");
// try moving it to a newly created canvas
c = (Canvas)XamlReader.Load (@"
<Canvas
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" >
<Border x:Name=""border"" />
</Canvas>
");
Canvas c2 = new Canvas ();
b = (Border)c.FindName("border");
c.Children.Remove (b);
c2.Children.Add (b);
Assert.IsNull (c.FindName("border"), "3");
Assert.IsNull (c2.FindName("border"), "4");
// try moving it to a XamlReader.Load'ed canvas
c = (Canvas)XamlReader.Load (@"
<Canvas
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" >
<Border x:Name=""border"" />
</Canvas>
");
c2 = (Canvas)XamlReader.Load (@"
<Canvas
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" />
");
b = (Border)c.FindName("border");
c.Children.Remove (b);
c2.Children.Add (b);
Assert.IsNull (c.FindName("border"), "5");
Assert.IsNotNull (c2.FindName("border"), "6");
// try adding it in a situation where it'll cause a name conflict
c = (Canvas)XamlReader.Load (@"
<Canvas
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" >
<Border x:Name=""border"" />
</Canvas>
");
c2 = (Canvas)XamlReader.Load (@"
<Canvas
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" >
//.........这里部分代码省略.........
示例6: NonVisualTypes
public void NonVisualTypes ()
{
Canvas c = (Canvas)XamlReader.Load (@"
<Canvas
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" >
<Canvas.Background>
<SolidColorBrush x:Name=""brush"" Color=""Green""/>
</Canvas.Background>
</Canvas>
");
// just for sanity's sake
Assert.IsNotNull (c.FindName("brush"), "0");
Brush b = c.Background;
// Clear the property and check if that clears the name
c.ClearValue (Panel.BackgroundProperty);
Assert.IsNull (c.FindName("brush"), "1");
// see if the name is reregistered when we add it back
c.Background = b;
Assert.IsNotNull (c.FindName("brush"), "2");
c = (Canvas)XamlReader.Load (@"
<Canvas
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" >
<Canvas.Background>
<SolidColorBrush x:Name=""brush"" Color=""Green""/>
</Canvas.Background>
</Canvas>
");
// setting to null?
c.Background = null;
Assert.IsNull (c.FindName("brush"), "3");
// what happens when we "reparent" a nonvisual type? does it's name move?
c = (Canvas)XamlReader.Load (@"<Canvas
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" >
<Canvas.Background>
<SolidColorBrush x:Name=""brush"" Color=""Green""/>
</Canvas.Background>
</Canvas>");
Canvas c2 = new Canvas();
c2.Background = (Brush)c.FindName("brush");
// it's still visible in the original canvas
Assert.IsNotNull (c.FindName ("brush"), "4");
// but not in the newly created one.
Assert.IsNull (c2.FindName ("brush"), "5");
// let's try a XamlReader.Load'ed canvas
c2 = (Canvas)XamlReader.Load (@"<Canvas
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" />");
c2.Background = (Brush)c.FindName ("brush");
// it's still visible in the original canvas
Assert.IsNotNull (c.FindName ("brush"), "6");
// and it's still not visible in the newly created one.
Assert.IsNull (c2.FindName ("brush"), "7");
// let's try removing it from the first tree before adding it to the second
c = (Canvas)XamlReader.Load (@"<Canvas
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" >
<Canvas.Background>
<SolidColorBrush x:Name=""brush"" Color=""Green""/>
</Canvas.Background>
</Canvas>");
c2 = (Canvas)XamlReader.Load (@"<Canvas
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" />");
b = c.Background;
c.ClearValue (Panel.BackgroundProperty);
c2.Background = b;
// it's not visible in the original canvas
Assert.IsNull (c.FindName ("brush"), "8");
// and now it's visible in the new scope
Assert.IsNotNull (c2.FindName ("brush"), "9");
// try removing it from the first tree before adding it to the second when there's a conflict
c = (Canvas)XamlReader.Load (@"<Canvas
//.........这里部分代码省略.........
示例7: BuiltinPropertyFindName
public void BuiltinPropertyFindName ()
{
Canvas c = new Canvas ();
ConcreteFrameworkElement cf1 = new ConcreteFrameworkElement ();
cf1.Name = "MyName";
c.Children.Add (cf1);
Assert.IsNull (c.FindName ("MyName"), "1");
}
示例8: LayoutManager
/// <summary>
/// Constructor for a LayoutManager instance.
/// </summary>
/// <param name="pTarget">Target canvas which will hold all photo slices and this manager will take effect on.</param>
/// <param name="pDataSource">Data source for this manager instance.</param>
/// <param name="pBtnSortCanvas">Sort layout trigger canvas.</param>
/// <param name="pBtnRandomCanvas">Random layout trigger canvas.</param>
/// <param name="pZoomOutTrigger">Zoomout trigter canvas.</param>
/// <param name="pSortNavi">Sort navigator.</param>
public LayoutManager(Canvas pTarget, PhotoDataSet pDataSource, Canvas pBtnSortCanvas, Canvas pBtnRandomCanvas, Canvas pZoomOutTrigger, SortNavigator pSortNavi, GenuineSlice pGenuineSlice, TracingIcon pTracingIcon, Image pScreenArrowLeft, Image pScreenArrowRight)
{
_target = pTarget;
_targetShadow = pTarget.FindName("PhotoHolderShadow") as Canvas;
_sortNavi = pSortNavi;
_dataSource = pDataSource;
_zoomOutTrigger = pZoomOutTrigger;
_btnSort = pBtnSortCanvas;
_btnSort.Cursor = Cursors.Hand;
_btnRandom = pBtnRandomCanvas;
_btnRandom.Cursor = Cursors.Hand;
_genuineSlice = pGenuineSlice;
_isSliceRequest = false;
_tracingMouse = pTracingIcon;
_screenArrowLeft = pScreenArrowLeft;
_screenArrowRight = pScreenArrowRight;
// Generate random & sort params
GenerateLayoutPostion();
// Fill thums to thumHolder
FillThumHolder();
// Event register.
_target.MouseLeftButtonUp += new MouseEventHandler(_target_MouseLeftButtonUp);
_zoomOutTrigger.MouseLeftButtonUp += new MouseEventHandler(_zoomOutTrigger_MouseLeftButtonUp);
_zoomInStoryboard = _target.FindName("ZoomIn") as Storyboard;
_zoomOutStoryboard = _target.FindName("ZoomOut") as Storyboard;
_rotateToAngleStoryboard = _target.FindName("RotateToAngle") as Storyboard;
_animateToPositionStoryboard = _target.FindName("AnimateToPosition") as Storyboard;
_zoomInStoryboard.Completed += new EventHandler(_zoomInStoryboard_Completed);
_zoomOutStoryboard.Completed += new EventHandler(_zoomOutStoryboard_Completed);
_layoutStandByStoryboard = _target.FindName("LayoutStandBy") as Storyboard;
_layoutStandByStoryboard.Completed += new EventHandler(_layoutStandByStoryboard_Completed);
_btnSort.MouseLeftButtonUp += new MouseEventHandler(_btnSort_MouseLeftButtonUp);
_btnSort.MouseEnter += new MouseEventHandler(_btnSort_MouseEnter);
_btnSort.MouseLeave += new EventHandler(_btnSort_MouseLeave);
_btnRandom.MouseLeftButtonUp += new MouseEventHandler(_btnRandom_MouseLeftButtonUp);
_btnRandom.MouseEnter += new MouseEventHandler(_btnRandom_MouseEnter);
_btnRandom.MouseLeave += new EventHandler(_btnRandom_MouseLeave);
_screenArrowLeft.MouseLeftButtonUp += new MouseEventHandler(_screenArrowLeft_MouseLeftButtonUp);
_screenArrowRight.MouseLeftButtonUp += new MouseEventHandler(_screenArrowRight_MouseLeftButtonUp);
// By default, enter sorted layout.
_status = AlbumStatus.Hanging; // clear status
Status = AlbumStatus.Sorted;
_zoomStatus = ZoomStatus.Out;
}
示例9: Init
public void Init(Canvas root)
{
Current = this;
this.content = root;
// register the scriptable endpoints
WebApplication.Current.RegisterScriptableObject("page", this);
game = new Game(root);
stats = new Stats(root);
help = new Help(root);
level = new Level("__empty__", game.world, game.foreground, game.background);
Canvas gamehost = root.FindName("gamehost") as Canvas;
gamehost.Children.Add(game);
Canvas statshost = root.FindName("statshost") as Canvas;
statshost.Children.Add(stats);
Canvas helphost = root.FindName("helphost") as Canvas;
helphost.Children.Add(help);
continueInfo = root.FindName("continue") as Canvas;
timer.Attach(root, "game-loop", new Timer.TickDelegate(GameTick), new TimeSpan(TimeSpan.TicksPerSecond/120));
keyboard.Init(root, new Keyboard.KeyEventDelegate(KeyPress));
SwitchLevel(levels[currentLevel]);
}
示例10: Arrow
public Arrow()
{
System.IO.Stream s = this.GetType().Assembly.GetManifestResourceStream( "Next2Friends.Swoosher.Arrow.xaml" );
root = (Canvas)this.InitializeFromXaml( new System.IO.StreamReader( s ).ReadToEnd() );
angle = (RotateTransform)root.FindName( "angle" );
}
示例11: BoardDisplay
public BoardDisplay()
{
// Initialize from XAML and get references to child elements
_root = XamlReader.Load(Utility.GetXamlResource("SilverlightSudokuHelper.BoardDisplay.xaml")) as Canvas;
_fadeStoryboard = _root.FindName("FadeStoryboard") as Storyboard;
_fadeAnimation = _root.FindName("FadeAnimation") as DoubleAnimation;
// Create the board frame
_frame = new Rectangle();
_frame.Fill = new SolidColorBrush { Color = Colors.White };
_frame.Stroke = new SolidColorBrush { Color = Colors.Black };
_frame.StrokeThickness = 2;
_frame.RadiusX = 5;
_frame.RadiusY = 5;
_root.Children.Add(_frame);
// Create the board lines
_verticalLines = new Line[Board.Size - 1];
_horizontalLines = new Line[Board.Size - 1];
for (var i = 0; i < _verticalLines.Length; i++)
{
bool majorLine = (0 == ((i + 1) % 3));
var verticalLine = new Line();
verticalLine.Stroke = new SolidColorBrush { Color = (majorLine ? Colors.Black : Colors.Gray) };
verticalLine.StrokeThickness = 2;
verticalLine.SetValue(Canvas.ZIndexProperty, (majorLine ? 1 : 0));
_root.Children.Add(verticalLine);
_verticalLines[i] = verticalLine;
var horizontalLine = new Line();
horizontalLine.Stroke = new SolidColorBrush { Color = (majorLine ? Colors.Black : Colors.Gray) };
horizontalLine.StrokeThickness = 2;
horizontalLine.SetValue(Canvas.ZIndexProperty, (majorLine ? 1 : 0));
_root.Children.Add(horizontalLine);
_horizontalLines[i] = horizontalLine;
}
// Create the selection marker
_marker = new Marker("SilverlightSudokuHelper.MarkerSelection.xaml");
_root.Children.Add(_marker);
_markerPosition = new Point(4, 4);
// Create the conflict marker
_conflict = new Marker("SilverlightSudokuHelper.MarkerConflict.xaml");
_root.Children.Add(_conflict);
// Create the value and candidate text blocks
_values = new TextBlock[Board.Size, Board.Size];
_candidates = new TextBlock[Board.Size, Board.Size, 9];
for (var y = 0; y < Board.Size; y++)
{
for (var x = 0; x < Board.Size; x++)
{
var value = new TextBlock { FontFamily = FontFamily };
_root.Children.Add(value);
_values[x, y] = value;
for (var z = 0; z < 9; z++)
{
var candidate = new TextBlock { FontFamily = FontFamily, Foreground = new SolidColorBrush { Color = Colors.Gray } };
_root.Children.Add(candidate);
_candidates[x, y, z] = candidate;
}
}
}
// Handle the Loaded event to do layout
Loaded += new RoutedEventHandler(HandleLoaded);
// Attach the constructed object to make it visible
Content = _root;
}