应用控制模板修改

时间:2019-05-16 08:42:10

标签: c# xaml templates controltemplate attached-properties

我使用附加属性来更改控件模板的多个属性,如下所示:

public override void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
    if (sender is MenuItem item)
    {
        if (item.Template.LoadContent() is FrameworkElement element)
        {
            if (element.FindName("borderRoot") is Border b)
            {
                b.Margin = new Thickness(5);
                b.BorderThickness = new Thickness(5);
                b.BorderBrush = new SolidColorBrush(Colors.Yellow);
            }
        }
    }
}

我的问题是,使用上述方法未应用更改。根本没有可见的变化。

我尝试使用ApplyTemplate方法应用模板,但没有任何结果: element.ApplyTemplate();

为什么?如何正确更新控件模板属性?

0 个答案:

没有答案
相关问题