0

我对使用 silverlight 5 中名为 pivotviewer 的新控件的 silverlight 非常陌生。我正在尝试从现有的 silverlight 4 代码中为枢轴查看器编写双击事件。

//double click event
private void PivotViewerControl_ItemDoubleClicked(object sender, ItemEventArgs e)
{
    PivotItem piv_item =PivotViewerControl1.GetItem(e.ItemId);

    if (!string.IsNullOrWhiteSpace(piv_item.Href))
    {
        PivotViewerControl1.CurrentItemId = e.ItemId;
        OpenLink(piv_item.Href);
    }
    else
    {
        MessageBox.Show("No Web Page...");
    }
}

在将其转换为内置 pivotviewer 控件的 silverlight 5 时,将为事件创建以下存根。

private void PivotViewerControl_ItemDoubleClicked(object sender, PivotViewerItemDoubleClickEventArgs e)
{  
   //here the pivotviewercontrol has not getitem()  in silverlight 5 so How do i get the currently selected 
   //Item on the double click
}

此外,我没有让页面上的图像自行加载。我的页面加载代码如下

public MainPage()
{
    InitializeComponent();
    PivotViewerControl.Loaded += PivotViewerControl_Loaded;
}

void PivotViewerControl_Loaded(object sender, RoutedEventArgs e)
{
    _cxml = new CxmlCollectionSource(new Uri(MauritiusCollectionUri, UriKind.RelativeOrAbsolute));
    _cxml.StateChanged += _cxml_StateChanged;
}

void _cxml_StateChanged(object sender, CxmlCollectionStateChangedEventArgs e)
{
    if (e.NewState == CxmlCollectionState.Loaded)
    {                          
        PivotViewerControl.PivotProperties = _cxml.ItemProperties.ToList();
        PivotViewerControl.ItemTemplates =_cxml.ItemTemplates;
        PivotViewerControl.ItemsSource =_cxml.Items;
    }
}

在运行时,我只在排序或进行搜索时才获得图像,谁能告诉我为什么?谢谢

4

1 回答 1

0

嗨,我能够翻译的双击事件如下

    private void PivotViewerControl_ItemDoubleClicked(object sender,   
    PivotViewerItemDoubleClickEventArgs e)
    {
        PivotViewerItem piv_item = (PivotViewerItem)e.Item;
        if(piv_item.Properties[0]!=null && piv_item.Properties[0].ToString()!=string.Empty)
        {
            OpenLink(piv_item.GetPropertyValue("Href")[0].ToString());
        }
}
于 2013-05-28T11:52:44.130 回答