我已经在ManipulationDelta这样做自己,但它并不平坦所有
在类属性
x:local="clr-namespace:YourApplicationNamespace"
在XAML:
<Grid x:Name="LayoutRoot" ManipulationDelta="LayoutRoot_ManipulationDelta">
<Grid.Resources>
<local:CustomSettings x:Key="Settings"/>
<DataTemplate x:Key="verseDataTemplate">
<TextBlock FontSize="{Binding Path=Font35, Source={StaticResource Settings}}"
Text="{Binding}"/>
</DataTemplate>
</Grid.Resources>
<ListBox ItemTemplate="{StaticResource verseDataTemplate}"/>
在后面的代码
:
private void LayoutRoot_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
try
{
var fnt = lboVerses.FontSize;
if (e.DeltaManipulation.Scale.X == 0 || e.DeltaManipulation.Scale.Y == 0) return;
if (e.DeltaManipulation.Scale.X > 1 || e.DeltaManipulation.Scale.Y > 1)
{
if (fnt < 72)
BibliaSettings.font35++;
}
else if (e.DeltaManipulation.Scale.X < 1 || e.DeltaManipulation.Scale.Y < 1)
{
if (fnt > 5)
BibliaSettings.font35--;
}
}
catch (Exception x)
{
Debugger.Log(0, "Errors", x.Message + "\n" + x.StackTrace);
}
}
您的CustomSettings类
public class CustomSettings : INotifyPropertyChanged
{
public static List<CustomSettings> Instances;
public CustomSettings()
{
if (Instances == null) Instances = new List<CustomSettings>();
Instances.Add(this);
}
public static int font35
{
get
{
return Get("Font35", 35); //Provide mechanism to get settings
}
set
{
Save(value, "Font35");//Provide mechanism to store settings
Instances.ForEach(inst => inst.OnPropertyChanged("Font35"));
}
}
public int Font35
{
get
{
return font35;
}
set
{
font35=value;
}
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
感谢您的回复。按我所说的文本缩放,它应该增加和减少ListBox内的字体大小。那么你能指点我一个代码示例吗? – Daniel 2010-12-20 16:25:00
我在这个列表框中显示来自圣经的经文,但是我想保持滚动功能,以便用户可以滚动选定章节的经文。不知道这是否澄清了这个概念。 – Daniel 2010-12-20 17:34:24
@Daniel你不需要一个Listbox就可以滚动。只需将文本包装在ScrollViewer中即可。 – 2010-12-20 17:46:47