Windows应用商店应用中的背景Z索引

时间:2013-11-13 18:58:38

标签: c# xaml windows-store-apps

我需要在我的Windows应用商店应用中设置图像背景。

但是当我这样做时,如下面的代码所示,图像覆盖了所有控件,我只能看到这个图像不能控制,如何解决这个问题?

我看不到任何ZIndex属性,但Canvas.ZIndex设置不起作用。

查看:

<Grid.Background>
        <ImageBrush ImageSource="{Binding BackgroundSource}" />
</Grid.Background>

视图模型:

    private string _backgroundSource;
    public string BackgroundSource
    {
        get { return _backgroundSource; }
        set { _backgroundSource = value; RaisePropertyChanged(() => BackgroundSource); }
    }

   BackgroundSource = "Assets/Background/White.png";

1 个答案:

答案 0 :(得分:2)

您的问题在于如何组织您的可视树。在没有看到整个结构的情况下,实现目标的一种快速简便的方法就是让你的背景片落后于其他一切。例如;

如果您说父母Grid目前喜欢;

<Grid>
   <Grid.Background>
       <ImageBrush ImageSource="{Binding BackgroundSource}" />
   </Grid.Background>

   <AllYourControls/>

</Grid>

您可以通过执行此类操作来解决此问题;

<Grid>

  <Grid>
     <Grid.Background>
         <ImageBrush ImageSource="{Binding BackgroundSource}" />
     </Grid.Background>
  </Grid>

   <AllYourControls/>

</Grid>

或嵌入它;

<Grid>
   <Grid.Background>
       <ImageBrush ImageSource="{Binding BackgroundSource}" />
   </Grid.Background>

   <Grid>
      <AllYourControls/>
   </Grid>

</Grid>

有多种方法可以通过树中的一个小组织来实现您的要求,并避免任何z-index或其他hacky技巧。

希望这有帮助。