我犯了一个解决方案,它有效,但它相当笨拙。(我没有足够的时间深入研究它。)如果有人建议一个合适的(可重用的,真正面向对象的:-)等)解决方案,我将不胜感激。
您必须在新类中实现ISemanticZoomInformation接口。
我没有找到关于界面如何工作的非常详细的描述,所以我不得不尝试了很多。我的问题是,当您点击 zoomedOutView 中的磁贴时,需要一个 scrollViewer 才能跳转到 zoomedIn 视图中的某个点。我不能从 scrollViewer 类继承。可能你需要继承一个 GridView 的子类,它有一个 scrollViewer 作为一个子类(如果可能的话)。在我的解决方案中(非常错误地)假设它有一个 scrollViewer 子级。另一个问题是,如果你捏,MakeVisible 方法会被调用,并且 item.Bounds.Left 将是 0.5(在这种情况下,你不想在 zoomedIn 视图中滚动到任何地方),但是如果你点击一个zoomedOut 视图中的元素,您必须在代码中设置此值,在这种情况下,
例如:
public class GridWithSemanticZoomInformation : Grid , ISemanticZoomInformation
{
private SemanticZoom _semanticZoomOwner;
private Boolean _IsZoomedInView;
private Boolean _IsActiveView;
public void CompleteViewChange()
{
//
}
public void CompleteViewChangeFrom(SemanticZoomLocation source, SemanticZoomLocation destination)
{
this.IsActiveView = false;
}
public void CompleteViewChangeTo(SemanticZoomLocation source, SemanticZoomLocation destination)
{
this.IsActiveView = true;
}
public void InitializeViewChange()
{
//
}
public bool IsActiveView
{
get
{
return this._IsActiveView;
}
set
{
this._IsActiveView = value;
}
}
public bool IsZoomedInView
{
get
{
return this._IsZoomedInView;
}
set
{
this._IsZoomedInView = value;
}
}
public void MakeVisible(SemanticZoomLocation item)
{
this.SemanticZoomOwner.IsZoomedInViewActive = (this.Equals(this.SemanticZoomOwner.ZoomedInView));
if (item.Bounds.Left != 0.5)
{
if (this.Children.Count() == 1)
{
foreach (UIElement element in this.Children)
{
if (element.GetType() == typeof(ScrollViewer))
{
((ScrollViewer)element).ScrollToHorizontalOffset(item.Bounds.Left);
}
}
}
}
}
public SemanticZoom SemanticZoomOwner
{
get
{
return this._semanticZoomOwner;
}
set
{
this._semanticZoomOwner = value;
}
}
public void StartViewChangeFrom(SemanticZoomLocation source, SemanticZoomLocation destination)
{
//
}
public void StartViewChangeTo(SemanticZoomLocation source, SemanticZoomLocation destination)
{
//
}
}
当您点击 zoomedOut 视图中的项目时,我为这些案例编写了一些笨拙的事件处理程序:
SemanticZoomLocation moveTo = new SemanticZoomLocation();
moveTo.Bounds = new Rect(0, 0, 0, 0);
this.ZoomedOutGrid.InitializeViewChange();
this.ZoomedInGrid.InitializeViewChange();
this.ZoomedOutGrid.StartViewChangeFrom(new SemanticZoomLocation(), new SemanticZoomLocation());
this.ZoomedInGrid.StartViewChangeTo(new SemanticZoomLocation(), moveTo);
this.ZoomedInGrid.MakeVisible(moveTo);
this.ZoomedOutGrid.CompleteViewChangeFrom(new SemanticZoomLocation(), new SemanticZoomLocation());
this.ZoomedInGrid.CompleteViewChangeTo(new SemanticZoomLocation(), new SemanticZoomLocation());
this.ZoomedOutGrid.CompleteViewChange();
this.ZoomedInGrid.CompleteViewChange();
}
private void SecondButton_Tapped(object sender, TappedRoutedEventArgs e)
{
SemanticZoomLocation moveTo = new SemanticZoomLocation();
moveTo.Bounds = new Rect(270, 0, 0, 0);
this.ZoomedOutGrid.InitializeViewChange();
this.ZoomedInGrid.InitializeViewChange();
this.ZoomedOutGrid.StartViewChangeFrom(new SemanticZoomLocation(), new SemanticZoomLocation());
this.ZoomedInGrid.StartViewChangeTo(new SemanticZoomLocation(), moveTo);
this.ZoomedInGrid.MakeVisible(moveTo);
this.ZoomedOutGrid.CompleteViewChangeFrom(new SemanticZoomLocation(), new SemanticZoomLocation());
this.ZoomedInGrid.CompleteViewChangeTo(new SemanticZoomLocation(), moveTo);
this.ZoomedOutGrid.CompleteViewChange();
this.ZoomedInGrid.CompleteViewChange();
}