当前位置: 首页>>代码示例>>C#>>正文


C# StackPanel.RegisterName方法代码示例

本文整理汇总了C#中System.Windows.Controls.StackPanel.RegisterName方法的典型用法代码示例。如果您正苦于以下问题:C# StackPanel.RegisterName方法的具体用法?C# StackPanel.RegisterName怎么用?C# StackPanel.RegisterName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.StackPanel的用法示例。


在下文中一共展示了StackPanel.RegisterName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateControls

        /// <summary>
        /// Generate textboxes for hex representation dynamically based on the user data length
        /// </summary>
        /// <param name="data"> Maximum user memory data received from the module</param>
        private void GenerateControls(byte [] data)
        {
            bool islastHexBytesAddedToHexEdtr = false;

            int datalength = data.Length;
            
            // Create a new label to represent next address eg: 0x0001, 0x0002 etc
            Label lblHexAddressRepEmptySpace = new Label();
            lblHexAddressRepEmptySpace.Height = 30;
            lblHexAddressRepEmptySpace.Width = 57;
            lblHexAddressRepEmptySpace.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            lblHexAddressRepEmptySpace.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            lblHexAddressRepEmptySpace.Content = "";
            stkpnlHexClmnAddress.Children.Add(lblHexAddressRepEmptySpace);
            // Create a name scope for the hex address stackpanel. 
            NameScope.SetNameScope(stkpnlHexClmnAddress, new NameScope());
            for (int i = 0; i < 16; i++)
            {
                // Create a new label to represent next address eg: 0x0001, 0x0002 etc
                Label lblHexAddressRep = new Label();
                lblHexAddressRep.Height = 30;
                lblHexAddressRep.Width = 57;
                lblHexAddressRep.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                lblHexAddressRep.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                lblHexAddressRep.Content = "0x" + (i).ToString("x4"); ;
                stkpnlHexClmnAddress.Children.Add(lblHexAddressRep);
            }

            StackPanel stkPannel = new StackPanel();
            stkPannel.Orientation = Orientation.Horizontal;
            stkPannel.Name = "stkpnlHexAddress0";
            stkPannel.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            stkPannel.VerticalAlignment = System.Windows.VerticalAlignment.Top;

            // Cache textboxes which is to be used for editing and writing back to the tag
            txtbxHexRepList = new TextBox[data.Length];
            
            // Create a name scope for the stackpanel. 
            NameScope.SetNameScope(stkPannel, new NameScope());
            
            // Create a label Hex word address eg: 0x0000 and add it to the stack panel
            Label lblHexAddress = new Label();
            lblHexAddress.Content = "0x0000";          
            lblHexAddress.Height = 30;
            lblHexAddress.Width = 57;
            lblHexAddress.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            lblHexAddress.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            stkPannel.Children.Add(lblHexAddress);

            for (int i = 1; i <= data.Length; i++)
            {
                islastHexBytesAddedToHexEdtr = true;
                // Create the textbox to hold the user byte data
                TextBox txtbxhexAddressed = new TextBox();

                CommandBinding txtbxhexAddressedCutCmdBnd = new CommandBinding(ApplicationCommands.Cut);
                txtbxhexAddressedCutCmdBnd.CanExecute += new CanExecuteRoutedEventHandler(txtbxhexAddressedCutCmdBnd_CanExecute);
                txtbxhexAddressedCutCmdBnd.Executed += new ExecutedRoutedEventHandler(txtbxhexAddressedCutCmdBnd_Executed);

                CommandBinding txtbxhexAddressedPasteCmdBnd = new CommandBinding(ApplicationCommands.Paste);
                txtbxhexAddressedPasteCmdBnd.CanExecute += new CanExecuteRoutedEventHandler(txtbxhexAddressedPasteCmdBnd_CanExecute);
                txtbxhexAddressedPasteCmdBnd.Executed += new ExecutedRoutedEventHandler(txtbxhexAddressedPasteCmdBnd_Executed);
                txtbxhexAddressed.CommandBindings.Add(txtbxhexAddressedCutCmdBnd);
                txtbxhexAddressed.CommandBindings.Add(txtbxhexAddressedPasteCmdBnd);

                // register the event
                txtbxhexAddressed.PreviewTextInput +=new TextCompositionEventHandler(this.txtblk0ByteAddressClmn1_PreviewTextInput);
                txtbxhexAddressed.PreviewKeyDown += new KeyEventHandler(this.txtblk0ByteAddressClmn1_PreviewKeyDown);
                txtbxhexAddressed.IsUndoEnabled = false;       
                txtbxhexAddressed.Name = "txtNumber"+i.ToString();
                txtbxhexAddressed.Text = "00";
                txtbxhexAddressed.CaretBrush = Brushes.Black;
                txtbxhexAddressed.Background = (SolidColorBrush)new BrushConverter().ConvertFrom("#0A000000");
                txtbxhexAddressed.TextAlignment = TextAlignment.Center;
                txtbxhexAddressed.Height = 30;
                txtbxhexAddressed.Width = 57;
                txtbxhexAddressed.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                txtbxhexAddressed.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                txtbxhexAddressed.MaxLength = 2;
                txtbxHexRepList[i - 1] = txtbxhexAddressed;   
                        
                if (i % 16 == 0)
                {
                    // 16 bytes on each row

                    // Add 16th byte in the stack panel
                    stkPannel.Children.Add(txtbxhexAddressed);
                    // To get original event handler to work by registering the name and 
                    // This will then allow us to call FindName on the StackPanel and find the TextBox.
                    stkPannel.RegisterName(txtbxhexAddressed.Name, txtbxhexAddressed);

                    // Add the stackpanel with maximum 16 bytes to the parent stackpanel
                    stkpnlByteAddress.Children.Add(stkPannel);

                    // To get original event handler to work by registering the name and 
                    // This will then allow us to call FindName on the parent stackPanel and find the child stackpanel.
//.........这里部分代码省略.........
开发者ID:colombmo,项目名称:itsi-gamification,代码行数:101,代码来源:ucUserMemory.xaml.cs


注:本文中的System.Windows.Controls.StackPanel.RegisterName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。