0

I need it to implement binding in setters.

Or are there any other workarounds to be able to set binding in style setters for Windows runtime?

norekhov
  • 3,915
  • 25
  • 45
  • You can't use a binding in a Setter. You can however modify the Template to use a binding, or add an Attached Property to apply the binding. – Nate Diamond Nov 05 '14 at 00:59
  • Are there any examples? I found an example for Silverlight but wasn't able to adapt it because I can't get DependecyProperty by name – norekhov Nov 05 '14 at 08:05
  • I just saw the Filip's answer here: http://stackoverflow.com/questions/11857505/how-do-i-do-bindings-in-itemcontainerstyle-in-winrt – Dani Dec 02 '14 at 15:06

1 Answers1

0

What kind of binding?

e.g.

<Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}"/>

Ok, then you should do something like this:

Here you can't bind a value to Padding.

<Style x:Key="GridViewItemStyle" TargetType="GridViewItem">
    <Setter Property="Padding" Value="0"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="GridViewItem">
                <GridViewItemPresenter Padding="{TemplateBinding Padding}" 
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

You can bind it that way:

<Style x:Key="GridViewItemStyle" TargetType="GridViewItem">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="GridViewItem">
                <GridViewItemPresenter Padding="{Binding PaddingValue}" 
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
Dani
  • 971
  • 12
  • 31