本文介紹使用獨立的xaml文件添加靜態資源的方式。code
// ImageButton.xaml <ResourceDictionary xmlns...> <Style x:Key="CustomImageButton" TargetType="Button"> ... </Style> </ResourceDictionary> // App.xaml <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/WpfApplication1;component/CustomControls/ImageButton.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> // 使用ImageButton的xaml <StackPanel> <Button Width="50" Height="30" Content="Button" FontSize="14" Style="{StaticResource CustomImageButton}" /> </StackPanel>