WPF控件的扩展附件属性

1.附加属性,采用依赖属性注册附件的方式:DependencyProperty.RegisterAttached,get与set要单独写,都是静态的;

#region HintFontWeight 字体加粗附加属性

        public static readonly DependencyProperty HintFontWeightProperty =
            DependencyProperty.RegisterAttached
            (
                "HintFontWeight",
                typeof(FontWeight),
                typeof(ControlAttachProperty),
                new FrameworkPropertyMetadata(FontWeights.Normal)
                );

        public static FontWeight GetHintFontWeight(DependencyObject obj)
        {
            return (FontWeight)obj.GetValue(HintFontWeightProperty);
        }

        public static void SetHintFontWeight(DependencyObject obj, FontWeight value)
        {
            obj.SetValue(HintFontWeightProperty, value);
        }

        #endregion

附件属性绑定到原生控件上,需要改控件的样式或模板

<Grid Grid.Column="1">
                            <TextBlock x:Name="Message"
                                       Padding="0"
                                       Visibility="Visible"
                                       Text="{TemplateBinding local:ControlAttachProperty.Hint}"
                                       FontWeight="{TemplateBinding local:ControlAttachProperty.HintFontWeight}"
                                       FontStyle="{TemplateBinding local:ControlAttachProperty.HintFontStyle}"
                                       Foreground="{TemplateBinding Foreground}"
                                       IsHitTestVisible="True"
                                       Opacity="0.5"
                                       HorizontalAlignment="Left"
                                       TextAlignment="Center"
                                       VerticalAlignment="Center"
                                       Margin="5,2,5,2" />
                        </Grid>

 

posted @ 2019-05-25 09:15  <--青青子衿-->  阅读(373)  评论(0编辑  收藏  举报
// /**/ // 在页脚Html代码 引入 // function btn_donateClick() { var DivPopup = document.getElementById('Div_popup'); var DivMasklayer = document.getElementById('div_masklayer'); DivMasklayer.style.display = 'block'; DivPopup.style.display = 'block'; var h = Div_popup.clientHeight; with (Div_popup.style) { marginTop = -h / 2 + 'px'; } } function MasklayerClick() { var masklayer = document.getElementById('div_masklayer'); var divImg = document.getElementById("Div_popup"); masklayer.style.display = "none"; divImg.style.display = "none"; } setTimeout( function () { document.getElementById('div_masklayer').onclick = MasklayerClick; document.getElementById('btn_donate').onclick = btn_donateClick; var a_gzw = document.getElementById("guanzhuwo"); a_gzw.href = "javascript:void(0);"; $("#guanzhuwo").attr("onclick","follow('33513f9f-ba13-e011-ac81-842b2b196315');"); }, 900);