- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我从全景图背后的代码将 FrameworkElements 添加到 PanoramaItem 时,会“选择”panoramaItem,从而导致非常糟糕的用户体验。
我做了一个小的测试项目,问题重现了。
MainPage 仅包含一个包含三个项目的全景图:
<Grid x:Name="LayoutRoot" Background="Transparent">
<phone:Panorama Name="m_Panorama">
<phone:PanoramaItem Header="Item 1"
Name="m_Item1">
<StackPanel Orientation="Vertical" Name="m_Stack1">
</StackPanel>
</phone:PanoramaItem>
<phone:PanoramaItem Header="Item 2"
Name="m_Item2">
<StackPanel Orientation="Vertical" Name="m_Stack2">
</StackPanel>
</phone:PanoramaItem>
<phone:PanoramaItem Header="Item 3"
Name="m_Item3">
<StackPanel Orientation="Vertical" Name="m_Stack3">
</StackPanel>
</phone:PanoramaItem>
</phone:Panorama>
</Grid>
后面的代码使用 DispatcherTimer 开始将元素添加到 PanoramaItems:
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (e.NavigationMode == NavigationMode.New){
StartDelayed(UpdateItem1, 1000);
StartDelayed(UpdateItem2, 1000);
StartDelayed(UpdateItem3, 1000);
}
}
private void AddTextblock(StackPanel stackPanel, string text, bool animate)
{
TextBlock tb = new TextBlock();
tb.Text = text;
stackPanel.Children.Add(tb);
if (animate){
tb.Measure(new Size(double.MaxValue, double.MaxValue));
tb.UpdateLayout();
Storyboard sb = new Storyboard();
DoubleAnimation anim = new DoubleAnimation();
anim.Duration = new Duration(TimeSpan.FromMilliseconds(500));
anim.From = 0;
anim.To = tb.DesiredSize.Width;
sb.Children.Add(anim);
Storyboard.SetTarget(anim, tb);
Storyboard.SetTargetProperty(anim, new PropertyPath("Width"));
sb.Begin();
}
}
private async void UpdateItem1(object sender, EventArgs e)
{
while (true){
m_Stack1.Children.Clear();
for (int i=0; i<10; i++){
await Task.Delay(500);
AddTextblock(m_Stack1, "This is item 1", false);
}
}
}
private async void UpdateItem2(object sender, EventArgs e)
{
while (true){
m_Stack2.Children.Clear();
for (int i=0; i<10; i++){
await Task.Delay(1000);
AddTextblock(m_Stack2, "This is item 2", false);
}
}
}
private async void UpdateItem3(object sender, EventArgs e)
{
while (true){
m_Stack3.Children.Clear();
for (int i=0; i<10; i++){
await Task.Delay(1500);
AddTextblock(m_Stack3, "This is item 3", false);
}
}
}
private static void StartDelayed(EventHandler handler, int milliseconds)
{
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(milliseconds);
if (handler != null)
timer.Tick += new EventHandler(handler);
timer.Tick += new EventHandler(OnLoadedTimerTick);
timer.Start();
} // StartDelayed
private static void OnLoadedTimerTick(object sender, EventArgs e)
{
DispatcherTimer timer = sender as DispatcherTimer;
if (timer != null)
timer.Stop();
} // OnLoadedTimerTick
}
如果您缓慢滚动全景图,就会发现问题:只要将一个项目添加到堆栈面板,全景图就会重新定位到包含添加元素的 PanoramaItem。
我的问题是:我做错了什么?如何避免全景选择panoramaItem?
最佳答案
一个快速的解决方案是将 StackPanel 封装在一个固定大小的容器中。
例如
<phone:PanoramaItem Header="Item 1" Name="m_Item1">
<ScrollViewer Height="1024">
<StackPanel Orientation="Vertical" Name="m_Stack1"/>
</ScrollViewer>
</phone:PanoramaItem>
我认为正在发生的事情是它正在动态调整元素及其容器的大小,从而导致您在水平滚动到下一个全景项目时看到的抖动。如果您愿意,可以将 ScrollViewer 的高度绑定(bind)到屏幕的高度以实现最佳使用。
关于c# - Windows 手机 8 : Add FrameworkElement to PanoramaItem from code behind,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25016287/
我正在使用 Panorama WP7 项目,我无法将我的 View 模型绑定(bind)到我的 View 。由于我的 View 是全景图,我想为第一个 PanoramaItem 设置一个 View 模
有没有办法在 Windows Phone 7 的 Silverlight 中将焦点设置到 PanoramaItem? 我已经尝试过: piResults.Focus(); 其中 piResults 是
注意:我已经看到 this它没有回答这个问题。 我有我的应用程序的首次运行体验,它向用户展示了几个不同的选项来解释应用程序的作用。如果他们选择这些选项之一,我想向他们展示 PanoramaItem处理
我正在开发一个具有动态数量的 PanoramaItems 的应用程序,目前这些都是通过使用其“ItemsSource”属性将它们的列表绑定(bind)到 Panorama 来添加的。 但是当我尝试向创
当我从全景图背后的代码将 FrameworkElements 添加到 PanoramaItem 时,会“选择”panoramaItem,从而导致非常糟糕的用户体验。 我做了一个小的测试项目,问题重现了
我是一名优秀的程序员,十分优秀!