據我所知,您需要重新使用視圖框,如果是這樣,請嘗試下一個解決方案作爲您的研究的起點。
XAML代碼:
<Window x:Class="ResourceDictionaryProblemHelpAttempt.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>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<ContentControl Grid.Row="0" ContentTemplate="{StaticResource DataTemplateWithViewBox}"></ContentControl>
<ContentControl Grid.Row="1" ContentTemplate="{StaticResource DataTemplateWithViewBox}"></ContentControl>
<ContentControl Grid.Row="2" ContentTemplate="{StaticResource DataTemplateWithViewBox}"></ContentControl>
</Grid>
資源字典碼
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="DataTemplateWithViewBox">
<Viewbox Width="16" Height="16">
<Rectangle Width="16" Height="16" Fill="Tomato" Stroke="Black" StrokeThickness="1"></Rectangle>
</Viewbox>
</DataTemplate>
的App.xaml代碼
<Application x:Class="ResourceDictionaryProblemHelpAttempt.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="ViewPortContainingResourceDictionary.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
問候。
「MyPicture.xaml」文件中沒有其他內容?這個想法背後的基本原理是什麼? – romanoza
沒有別的。我只想把這個ViewBox保存在一個外部文件中。 – Fruchtzwerg
所以你不能使用'ResourceDictionary'也不能控制/用戶控制?這真的很有趣,你爲什麼決定使用這種方法。 – romanoza