【发布时间】:2023-03-06 12:30:01
【问题描述】:
我想使用 MaterialDesign 将Expander 添加到我的项目中。添加时,我遇到以下错误。
如何访问TextBlocks 中的样式资源?
<Grid>
<materialDesign:Card>
<StackPanel>
<Expander HorizontalAlignment="Stretch" Header="Expander Example 2a">
<StackPanel Orientation="Vertical" TextBlock.Foreground="{DynamicResource MaterialDesignBody}" Margin="24,8,24,16">
<TextBlock Text="Your Content" />
<TextBlock Style="{StaticResource HorizontalExpanderContentTextBlock}" />
</StackPanel>
</Expander>
<Border Style="{StaticResource HorizontalDividerBorder}" />
<Expander HorizontalAlignment="Stretch" Header="Expander Example 2b">
<StackPanel Orientation="Vertical" TextBlock.Foreground="{DynamicResource MaterialDesignBody}" Margin="24,8,24,16">
<TextBlock Text="Your Content" />
<TextBlock Style="{StaticResource HorizontalExpanderContentTextBlock}" />
</StackPanel>
</Expander>
<Border Style="{StaticResource HorizontalDividerBorder}" />
<Expander HorizontalAlignment="Stretch" Header="Expander Example 2c">
<StackPanel Orientation="Vertical" TextBlock.Foreground="{DynamicResource MaterialDesignBody}" Margin="24,8,24,16">
<TextBlock Text="Your Content" />
<TextBlock Style="{StaticResource HorizontalExpanderContentTextBlock}" />
</StackPanel>
</Expander>
</StackPanel>
</materialDesign:Card>
</Grid>
错误:
Error The resource "HorizontalDividerBorder" could not be resolved.
Error The resource "HorizontalExpanderContentTextBlock" could not be resolved.
Error The resource "HorizontalDividerBorder" could not be resolved.
Error The resource "HorizontalExpanderContentTextBlock" could not be resolved.
Error The resource "HorizontalExpanderContentTextBlock" could not be resolved.
App.xaml代码:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
【问题讨论】:
标签: wpf xaml material-design expander