0

I have an application in which I set the width of the element in a property using MVVM.

My Style:

<Style x:Key="TileRootSquareGridStyleV2" TargetType="Grid">
         <Setter Property="Width" Value="{Binding DataContext.SquaredTileWidth , Mode=OneWay}" />
        <Setter Property="Height" Value="{Binding DataContext.SquaredTileWidth, Mode=OneWay}" />
    </Style>

My DataTemplate:

<DataTemplate x:Key="PhoneFeedTemplateV2">
        <Grid Margin="5"  Style="{StaticResource TileRootSquareGridStyleV2}"  >
 <TextBlock Text="{Binding SquaredTileWidth}"  />  
</Grid>
</DataTemplate>

I want to be able to reuse my style TileRootSquareGridStyleV2 but I am unable to set the properties Width and Height. the SquaredTileWidth property with in my object is correctly set because when I launch the application my textblock does show me a number.

Does anyone have an idea what I am doing wrong?

Edit: I have also tried:

<Style x:Key="TileRootSquareGridStyleV2" TargetType="Grid">
         <Setter Property="Width" Value="{Binding SquaredTileWidth , Mode=OneWay}" />
        <Setter Property="Height" Value="{Binding SquaredTileWidth, Mode=OneWay}" />
    </Style>

but no luck. However when I set the Height and Width on my Grid it works:

 <DataTemplate x:Key="PhoneFeedTemplateV2">
            <Grid Margin="5"  Width="{Binding SquaredTileWidth}"  Height="{Binding SquaredTileWidth}">
     <TextBlock Text="{Binding SquaredTileWidth}"  />  
    </Grid>
    </DataTemplate>

EDIT2: Ok so the answer is: Bindings are not supported on Setters....

Damien
  • 2,911
  • 1
  • 25
  • 47
  • 1
    Any errors in the Output Window? Binding errors often show there. If you, *experimentally* add the `Width`/`Height` binding to the Grid directly, does it work? – WiredPrairie Jun 03 '15 at 01:01
  • @WiredPrairie I have updated my question, but yes it works when I set the binding on the grid, however I would lick to be able to have it in the style if possible? – Damien Jun 03 '15 at 02:28
  • See also generalized work-around here: [As the platform evolves, so do the workarounds \[Better SetterValueBindingHelper makes Silverlight Setters better-er!\]](http://dlaa.me/blog/post/9916283) – Peter Duniho Jun 03 '15 at 02:57

0 Answers0