c# – 自定义视图层次结构的语义缩放,而不是纯网格或列表视图
作者:互联网
我在xaml中有一个页面布局,其中包含一个网格,其中有几个网格视图,表示不同的内容和各个样式.
这是我的应用程序的中心,它提供了这些不同的内容,例如:
艺术家,表演,记录以某种方式相关但内容不同,因此表现不同. (完全不同的itemtemplates和groupingstyle为每个)
我想实现一个语义缩放,一旦缩小,应该显示我拥有的自定义组.所以它应该在缩小时将艺术家,表演,录音作为群组展示.
不幸的是,我只能在ZoomedIn / Out标签内放置一个GridView或ListView.
有谁知道如何解决这个问题或者可以提供可靠的解决方案?
解决方法:
我可以找到解决方案,它可以工作,但它还是比较笨拙的. (我没有足够的时间深入研究它.)
如果有人建议一个合适的(可重用的,真正面向对象的:-)等解决方案,我真的很感激.
您必须在新类中实现ISemanticZoomInformation接口.
我没有找到关于界面如何工作的非常详细的描述,所以我不得不尝试很多.我的问题是,当你点击zoomedOutView中的一个磁贴时,需要一个scrollViewer能够跳转到zoomedIn视图中的某个点.我无法从scrollViewer类继承.可能你需要子类化GridView的子类,它有一个scrollViewer作为子项(如果可能的话).在我的解决方案中,(非常错误地)假设它有一个scrollViewer子项.另一个问题是,如果你捏,MakeVisible方法被调用,item.Bounds.Left将是0.5(在这种情况下你不想在任何地方的zoomedIn视图中滚动),但如果你点击一个在zoomedOut视图中,您必须在代码中设置此值,在这种情况下,您需要在MakeVisible方法中滚动scrollViewer.
例如.:
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视图中的项目时,我为这些案例写了一些笨拙的事件处理程序:
private void FirstButton_Tapped(object sender,TappedRoutedEventArgs e)
{
this.ZoomedOutGrid.SemanticZoomOwner.ToggleActiveView();
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();
}
标签:c,windows-8,winrt-xaml,semantic-zoom 来源: https://codeday.me/bug/20190625/1286424.html