【问题标题】:how to detect when data binding to UI elements (panorama and listbox) have completed in windows phone 7?如何检测到 UI 元素(全景和列表框)的数据绑定何时在 windows phone 7 中完成?
【发布时间】:2011-10-05 19:10:56
【问题描述】:

我在 Panorama 中有一个 Panorama 控件和 ListBox 控件。是否有任何“事件”我可以挂钩或以任何方式检测与全景和/或列表框控件关联的所有数据绑定或 UI 显示何时完成?

我需要检测此事件的原因是因为我只想在全景图和/或列表框控件完全绑定并完成渲染后才显示 ApplicationBar。

例如,我的 XAML 定义如下。

<controls:Panorama Name="panorama">
 <controls:Panorama.ItemTemplate>
  <DataTemplate>
   <ListBox ItemsSource="{Binding Details}">
    <ListBox.ItemTemplate>
     <DataTemplate>
      <TextBlock Text="{Binding Field1}"/>
      <TextBlock Text="{Binding Field2}"/>
      ...
      <TextBlock Text="{Binding FieldN}"/>
     </DataTemplate>
    </ListBox.ItemTemplate>
   </ListBox>
  </DataTemplate>
 </controls:Panorama.ItemTemplate>
</controls:Panorama>

我的普通 CLR 对象 (POCO) 如下所示。

public class MyPoco {
 List<Detail> Details { get; set; }
}
public class Detail {
 public string Field1 { get; set; }
 public string Field1 { get; set; }
 ...
 public string FieldN { get; set; }
}

在我的 c# 代码隐藏中,我按如下方式绑定数据。

List<MyPoco> pocos = GetMyPocosFromSomewhere();   
panorama.ItemsSource = myList;
ApplicationBar.IsVisible = true; //i only want to make this visible after the Panorama and ListBox controls have finished binding and rendering

现在,我在上面勾勒出的代码可以正常工作,但 ApplicationBar 在全景/列表框控件呈现之前始终可见。对我来说,这让用户体验很尴尬。

感谢任何帮助。

【问题讨论】:

    标签: windows-phone-7 panorama-control listbox-control


    【解决方案1】:

    简短的回答是“不,你无法检测到它”。

    但一个好的解决方案是将命令添加到 UI 工作队列中。调度员。像这样:

    Dispatcher.BeginInvoke(() => ApplicationBar.IsVisible = true);
    

    这样,当所有其他 UI 任务完成后,它会首先呈现它,并且体验应该不会那么尴尬。

    【讨论】:

    • 仅作记录,这适用于 UI 的 任何 更改。直接在 UI 线程上的常规更改被强制通过,其中 BeginInvoke 被排队。
    猜你喜欢
    • 1970-01-01
    • 2012-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-11
    相关资源
    最近更新 更多