【发布时间】:2023-04-04 12:14:01
【问题描述】:
我正在尝试在 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>
我真正想做的是将 RenderTransform 绑定到我的 ViewModel 的 Zoom 属性,但这是不允许的。我可以绑定到 FontSize 并正确更改 FontSize,但我必须在我的代码隐藏中对其进行硬编码。我真正想做的是尊重设计师设置的 FontSize 设置,并对所有 FontSize 应用统一缩放。所以在我后面的代码中:
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);
}
}
}
我无法访问 setter.Property.Name(编译时错误),尽管我可以看到它是 FontSize 在调试器中。并且值始终是“无法评估表达式” - 输出为空白。
任何线索,无论是关于这里发生了什么,还是更好的方法?
安德鲁
【问题讨论】:
标签: silverlight data-binding windows-phone-7