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>
  • 相关阅读:
    python出现local variable 'f' referenced before assiginment""
    使用Python修改ifcfg-eth0文件
    在linux中运行py文件时,及时知道错误信息
    分词结果准确率、召回率计算-python
    oozie工作流
    combiner hadoop
    Python常用模块--base64
    Python常用模块--datetime
    树莓派(Raspbian系统)中使用pyinstaller封装Python代码为可执行程序
    LeetCode刷题笔记--Python--28. 实现strStr()
  • 原文地址:https://www.cnblogs.com/bear831204/p/1415719.html
Copyright © 2011-2022 走看看