从项目中的另一个文件引用资源字典

时间:2021-06-16 05:57:14

标签: xml wpf xaml resourcedictionary

我有一个资源字典,里面有一个数据模板。

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero2"
        xmlns:fa="http://schemas.fontawesome.io/icons/">

    <DataTemplate x:Key="CircuitBreakerClose">
        <Grid>
            <Path Stroke="Green" Fill="Transparent" StrokeThickness="1" Stretch="Fill">
                <Path.Data>
                    <RectangleGeometry Rect="0,0,50,50"></RectangleGeometry>
                </Path.Data>
            </Path>
        </Grid>
    </DataTemplate>

</ResourceDictionary>

我正在尝试从其他文件中访问它。

<UserControl.Resources>
        <converters:UniqueIdImageSourceConverter x:Key="uniqueIdImageSourceConverter" />
        
        <ResourceDictionary x:Key="ResourceDictionary">
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="C:/Cfg/Screens/Themes/Resources/DynamicControlCircuitBreaker.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
        
        <DataTemplate x:Key="CircuitBreakerClose"/>

</UserControl.Resources>

    <DataTemplate>
        <Button>
            <StackPanel Orientation="Vertical">
               
                <ContentControl Content="{Binding}">
                    <ContentControl.Style>
                        <Style TargetType="{x:Type ContentControl}">
                            
                            <Setter Property="ContentTemplate" Value="{StaticResource CircuitBreakerClose}"/>
          
                            </Style>
                        </ContentControl.Style>
                    </ContentControl>
                
            </StackPanel>
        </Button>
    </DataTemplate>

我是 wpf 的新手,我无法显示它。我相信我没有正确地引用它。谁能解释一下如何引用资源字典中的资源。

0 个答案:

没有答案
相关问题