为什么Frame放置在ViewBox中时找不到本地资源?

时间:2017-07-03 15:09:12

标签: wpf xaml viewbox

我尝试使用< 框架 />控制在< ViewBox />内。 帧控制源是位于名为Pages的文件夹中的页面。

在页面中只有一个元素。用XAML矢量图像填充的矩形

为什么不显示任何内容?

<Window xmlns:shared="http://schemas.actiprosoftware.com/winfx/xaml/shared"
    x:Class="SearChForComp.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <Viewbox VerticalAlignment="Center" HorizontalAlignment="Center" >
        <Frame Source="Pages/mainPage.xaml" NavigationUIVisibility="Hidden" />
    </Viewbox>

</Grid>

这是我的页面(mainpage.xaml):

<Page x:Class="SearChForComp.Pages.mainPage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  mc:Ignorable="d" 

Title="mainPage">

<Grid>
    <Rectangle Fill="{StaticResource intro2}" />
</Grid>

我在app.xaml中定义了我的资源,如下所示:

<Application x:Class="SearChForComp.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         StartupUri="MainWindow.xaml">
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="VectorGrahics/intro2.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

Intro2.xaml是一个大文件。我发布了第一个和最后一个标签:

    <ResourceDictionary
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <DrawingBrush x:Key="intro2" Stretch="Uniform">
        <... \>
    </DrawingBrush>
</ResourceDictionary>

1 个答案:

答案 0 :(得分:1)

如果您设置WidthHeight的{​​{1}} / MinWidth或至少MinHeight / Rectangle,它应该会有效:

Page