在我的項目(ABC),我有MainWindow.xaml,我已經定義了一個工具欄,並此工具欄在 項目下的資源/視圖定義/ ApplicationToolbar.xmal如下:如何在WPF中的單獨ResourceDictionary中引用資源?
我在我的MainWindow.xaml中引用它爲xmlns:local="clr-namespace:ABC"
,一旦我運行它,我得到一個 錯誤,指示View123找不到。
的更多信息:(EDIT)
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ABC">
<StackPanel x:Key="View1">
<Button Margin="3" Content="Test1"></Button>
<Button Margin="3" Content="Test2"></Button>
</StackPanel>
</ResourceDictionary>
在MainWindow.xmal
現在有:
<Window x:Class="ABC.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ABC"
Title="MainWindow" Height="350" Width="525">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="10"/>
<RowDefinition Height="*"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<!-- FOLLOWING LINE CAUSING ERROR-->
<ContentControl Name="Toolbar" Content="{StaticResource View1 }"></ContentControl>
</Grid>
</Window>
我缺少什麼?
感謝, 阿米特
您能告訴我們您實際參考控件的位置嗎?這裏沒有足夠的信息來提出解決方案。 – 2012-08-14 17:13:54
@Jeff謝謝。我更新了我的問題 – 2012-08-14 17:21:34
您需要在您的MainWindow.xaml – 2012-08-14 17:23:28