zoukankan      html  css  js  c++  java
  • 一个自定义FrameworkElement的例子

    class:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Controls;
    using System.Windows;
    using System.Windows.Media;

    namespace WpfApplication25
    {
        
    public class MyTextBlock : FrameworkElement
        {
            TextBlock t;
            
    public MyTextBlock()
            {
                t 
    = new TextBlock() 
                {
                    Text 
    = "TextTextText",
                    Background 
    = Brushes.Blue,
                    Width 
    = 60,
                    Height 
    = 30
                };
                AddLogicalChild(t);
                AddVisualChild(t);
            }

            
    protected override Size MeasureOverride(Size availableSize)
            {
                t.Measure(availableSize);
                
    return base.MeasureOverride(availableSize);
            }

            
    protected override Size ArrangeOverride(Size finalSize)
            {
                t.Arrange(
    new Rect(new Point(5050), t.DesiredSize));
                
    return base.ArrangeOverride(finalSize);
            }

            
    // In order for the visual tree to be enumerated correctly,
            
    // we must override the GetVisualChild and VisualChildrenCount.
            protected override Visual GetVisualChild(int index)
            {
                
    return t;
            }

            
    protected override int VisualChildrenCount
            {
                
    get
                {
                    
    return 1;
                }
            }
        }
    }
    Xaml :
    <Window x:Class="WpfApplication25.Window1"
        xmlns
    ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x
    ="http://schemas.microsoft.com/winfx/2006/xaml"
        Title
    ="Window1" Height="300" Width="300"
            xmlns:local
    ="clr-namespace:WpfApplication25">
        
    <Grid>
            
    <local:MyTextBlock></local:MyTextBlock>
        
    </Grid>
    </Window>
  • 相关阅读:
    Robomaster电控入门(3)RM系列电机控制
    Robomaster电控入门(2)DR16&DT7接收与解码
    惊魂未定之Ubuntu重装显卡驱动
    ORB-SLAM demo测试
    Intel NUC5安装Kinect驱动踩坑
    Ubuntu下ROS&&Kinect&&ORB-SLAM环境搭建
    Robomaster电控入门(1)STM32开发环境搭建
    Robomaster电控入门(0)绪论
    WhaleCTF之隐写-Find
    WhaleCTF之web-本地登录
  • 原文地址:https://www.cnblogs.com/bear831204/p/1415719.html
Copyright © 2011-2022 走看看