Development Time Data for ControlTemplate

Providing development-time data for a DataContext is easy to use d:DataContext, but what about the control properties referenced {TemplateBinding}or {RelativeSource TemplatedParent}from Style.Template?

Should I just populate the sample data control inside the constructor / Loaded event when it DesignerProperties.GetIsInDesignMode(this)returns true? (Cannot do this because it will disrupt normal design).

What about third-party controls that I cannot change?

+5
source share
1 answer

For my own controls, I usually do something like:

<Style x:Key="FooStyle>
  <Setter Property="Template>
    <Setter.Value>
      <ControlTemplate TargetType="FooControl">
        <Grid d:DataContext="{d:DesignInstance FooDesignTimeData, IsDesignTimeCreatable=True}">
          ... guts of control template go here ...
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

"FooDesignTimeData" - , ( ).

, . , - , , , . , , , (, Vendor.Controls.Design.dll Vendor.Controls.Expression.Design. dll).

TemplateBindings, . , . ( , ), . GoToStateAction Blend SDK . , , "", . , , . , .

+2

All Articles