简体   繁体   中英

Why Frame does not find local resource when it's placed inside a ViewBox?

I tried to use a < Frame /> control inside a < ViewBox />. Source of Frame Control is a page that lay in folder named Pages.

And in the page there is just one element. A Rectangle that is filled with XAML vector image.

Why this is not display anything?

<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>

And this is My Page (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>

I defined my Resources in app.xaml like this:

<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>

And the Intro2.xaml is a large file. i post a first and last tags:

    <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>

如果您在Page中设置RectangleWidth / Height或至少MinWidth / MinHeight ,则它应该可以工作:

<Rectangle Fill="{StaticResource intro2}" MinWidth="1" MinHeight="1" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM