I’m trying to implement pinch/stretch zooming on a ListBox:
<ListBox
Grid.Row="1"
ManipulationCompleted="ListBox_ManipulationCompleted"
ItemsSource="{Binding Paras}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock
DataContext="{Binding}"
TextWrapping="Wrap"
Text="{Binding Text}"
FontSize="{Binding FontSize}">
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
What I really want to do is bind a RenderTransform to a Zoom property of my ViewModel but that’s not allowed. I can bind to the FontSize and it changes the FontSize correctly, but I have to hard code this in my code-behind. What I really want to do is honour the FontSize settings set by the designer and apply a uniform zoom to all the FontSizes. So in my code behind I have:
Style style = App.Current.Resources[_XElement.Name.LocalName] as Style;
if ( style != null )
{
foreach ( var s in style.Setters )
{
Setter setter = s as Setter;
if ( setter != null )
{
Debug.WriteLine(setter.Property + "=" + setter.Value);
}
}
}
I can’t access setter.Property.Name (compile time error) although I can see it is FontSize is in the debugger. And Value is always “Could not evaluate expression” – outputs as blank.
Any clues, either as to what’s going on here, or a better wayof doing it?
Andrew
You can’t access the
Namebecause the Silverlight implemenation ofDependencyPropertydoes not expose the name public. In order to pickup the Setters that set theFontSizeproperty you will need to use a little reflection to pick out of theStyle.TargetTypea static field called “FontSizeProperty” and extract its value. Then compare each setterPropertywith that value if you have a match then you have found the setter reponsible for theFontSize.