代码之家  ›  专栏  ›  技术社区  ›  Drake

仅对一个条目控件使用自定义呈现器

  •  0
  • Drake  · 技术社区  · 6 年前

    [assembly: ExportRenderer(typeof(Entry), typeof(CustomEntryRenderer))]
    namespace MyApp.Controls
    {
        public class CustomEntryRenderer : EntryRenderer
        {
            protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
            {
                base.OnElementChanged(e);
    
                if (this.Control != null)
                {
                    Control.Style = (Windows.UI.Xaml.Style)App.Current.Resources["CustomTextBoxStyle"];
                }
            }
        }
    }
    

    但我只想用在我的 Entry 控件,不是所有控件。我怎样才能做到这一点?

    1 回复  |  直到 6 年前
        1
  •  2
  •   Jason    6 年前

    创建从项继承的自定义控件MyEntry

    然后在渲染器中,指定它只应用于MyEntry类型

    [assembly: ExportRenderer(typeof(MyEntry), typeof(CustomEntryRenderer))]