Custom Ctl has a cs and template xaml, no code behind setup.
Need to think about Inject into Trigger system,2-way DataBinding
mark arbitrary child attachment for layout/count etc.
// TemplateBinding does not support two way, generic.xaml
so have to use full binding point to TemplateParent
Text={TemplateBinding Text} //control.Text is DP
Text ={Binding Text RelateiveSource={RelativeSource TemplateParent}}
[TemplatePart(Name="PART_TB",Type=typeof(TB)] // for designer only
TB {get;set { TextChaned-=; TextChange+= avoid Memory Leak}
OnApplyTemplate() {
TB=GetTemplateChild("PART_TB") as TB //connect generic.xaml <TB/> to prop TB
}
UIElem->FrameworkElem->Control->ContentCtl->HeadedCC->ItemCtl->Selector->RangeBase->Buildin
propdepreg propa
http://www.midity.com/content/visual-studio-2010-dependencyproperty-code-snippets-0
[Framework]PropertyMetaData([FrameworkPropertyMetaDataOptions.BindingTwoWayByDefault],
new PropDataChgedCB(cb), new CoerceValueCB(cb) //coerce ctl.val, VM no chg even twoWay
Read Only Dependency Prop, private set by key, inject into trigger system
generic.xaml <ControlTemplate.Triggers><Trigger prop="Going" value=true>
<Setter prop="Background" Value="Green" />
private static readonly DPKey GoingDPkey=DP.RegisterRO("Going",...);
public static readonly DP GoingDP=GoingDPKey.DependencyProperty; // connect key to DPval
public bool Going {return (bool) GetValue(GoingDP);} // regular prop
// private set using key.
OnApplyTemplate() { GetTemplateChild("PART_btn").Click+=(s,e)=>{SetValue(GoingDPKey,true);
Custom ctl uses attached Prop set on runtime child to count etc.
public static readonly DP RowProperty=DP.RegisterAttached("Row", ...);
public static int GetRow(DependencyObject obj) {return obj.GetVal(RowProp);}
public static void SetRow(DependencyObject obj,int i){obj.SetVal(RowProp,i);}
OnInit() { foreach(c in Panel.Children) {c.GetRow(c);...} // unknown content ahead of time.}
How generic Generic.xaml can be --- restricted by Presenter type only
<ControlTemplate><ContentPresenter> or <ItemPresenter> <BuildInCtrl />
then any other control injected by user of this control.
<ContentPresenter/> require CC: ContentControl --<cc>anything</cc>
<ItemsPresneter/> require CC: ItemsControl <cc> multi type multi things</cc>
Avoid Collection Type Singleton.
public static RO DP ItemsProp typeof(IList) default=ObsCol=> singleton
should set in ctor, OnApplyTemp, OnInit,
Generic.xaml can be <ListBox ItemsSource="{TemplateBinding Items}"/>
Friday, March 25, 2016
WPF Custom Control TemplateBinding and Property Declaration
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment