StackPanel不接受ResourceDictionary吗?

时间:2018-06-19 11:54:51

标签: wpf xaml resourcedictionary

我有这个ResourceDictionary:

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cc="clr-namespace:CoCa.Views.CustomControls"
xmlns:vm="clr-namespace:CoCa.ViewModel">

<Style BasedOn="{StaticResource LabelStyle1}" TargetType="{x:Type Label}">
    <Setter Property="Width" Value="130" />
    <Setter Property="Foreground" Value="{StaticResource DetailsForegroundBrush}" />
</Style>
<Style BasedOn="{StaticResource SPanel}" TargetType="{x:Type StackPanel}" />
<Style BasedOn="{StaticResource InputParm}" TargetType="{x:Type cc:InputParameter}">
    <Setter Property="Visibility" Value="Visible" />
    <Setter Property="LBForeground" Value="{StaticResource DetailsForegroundBrush}" />
    <Setter Property="TBForeground" Value="{StaticResource DetailsForegroundBrush}" />
    <Setter Property="TBBackground" Value="{StaticResource DetailsControlsBackgroundBrush}" />
</Style>
<Style BasedOn="{StaticResource Radio}" TargetType="RadioButton">
    <Setter Property="Foreground" Value="{StaticResource DetailsForegroundBrush}" />
</Style>
<Style BasedOn="{StaticResource ComboBoxStyle}" TargetType="{x:Type ComboBox}">
    <Setter Property="Background" Value="{StaticResource DetailsControlsBackgroundBrush}" />
    <Setter Property="Foreground" Value="{StaticResource DetailsForegroundBrush}" />
</Style>
<Style BasedOn="{StaticResource Items1}" TargetType="{x:Type ComboBoxItem}">
    <Setter Property="Background" Value="{StaticResource DetailsControlsBackgroundBrush}" />
    <Setter Property="Foreground" Value="{StaticResource DetailsForegroundBrush}" />
</Style>
<vm:IntToVisibility x:Key="intToVisibilityConverter" />
</ResourceDictionary>

我这样使用它:(删除了一些东西):

......  
<DataGrid.RowDetailsTemplate>
            <DataTemplate>
                <Border Margin="0" Style="{StaticResource DataGridDetailsBorder}">
                    <StackPanel
                        x:Name="MainPanel"
                        Margin="3,3,3,3"
                        Background="{StaticResource DetailsBackgroundBrush}"
                        DataContext="{Binding ElementName=DgSections, Path=SelectedItem, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                        Orientation="Vertical">

                        <StackPanel.Resources>
                            <ResourceDictionary>
                                <ResourceDictionary.MergedDictionaries>
                                    <ResourceDictionary Source="DataGridDetails.xaml" />
                                </ResourceDictionary.MergedDictionaries>
                            </ResourceDictionary>

                        </StackPanel.Resources>
                        <StackPanel x:Name="SectionType" Width="Auto">
                            <Label Content="Section type" />
                            <ComboBox
                                x:Name="SectionsComboBox"
                                 ....
                                SelectedValuePath="Key" />
                        </StackPanel>
                        <StackPanel x:Name="Material">
                            <StackPanel.Style>
 ....etc

整个给我一个错误(蓝色波浪状带下划线)。 错误提示:

 "Unable to cast object of type 'Microsoft.VisualStudio.DesignTools.Markup.DocumentModel.DocumentCompositeNode' to type 'System.Windows.ResourceDictionary'.    

在我使用字典的两个地方都出现了错误(意为)。 我怀疑它与设计上下文有关,因为该程序可以按其要求进行编译和运行。 我知道我可以避免这种构造,并在任何情况下都重复字典内容,但是为什么要重复代码? 但是错误是从哪里来的?

0 个答案:

没有答案