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....