我有两个文件: ButtonStyle.xaml和ConstantsStyle.xaml
在App.xaml中,我将初始化
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Zalo;component/ResourceDictionary/480x800/ConstantsStyle.xaml"/>
<ResourceDictionary Source="/Zalo;component/ResourceDictionary/480x800/ButtonStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
......
</Application.Resources>文件ConstantsStyle.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">
<Thickness x:Key="GenericButtonStylePadding">0,7</Thickness>
</ResourceDictionary>文件ButtonStyle.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
xmlns:usercontrols="clr-namespace:Zalo.UserControls">
<Style x:Key="GenericButtonStyle" TargetType="Button">
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="{StaticResource GenericButtonStylePadding}"/>
</Style>
</ResourceDictionary>应用程序崩溃运行时。因为找不到名称/密钥为GenericButtonStylePadding的资源?
如何正确运行app?请帮帮我
发布于 2015-05-11 13:12:10
尝试使用DyanamicResource而不是StaticResource
<Style x:Key="GenericButtonStyle" TargetType="Button">
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="{DynamicResource GenericButtonStylePadding}"/>
</Style>编辑:你可以测试一件事。向Constant.XAML添加另一个常量
<Brush x:Key="BGBrush">Black</Brush>试着在你的ButtonStyle.XAML中使用它
<Style x:Key="GenericButtonStyle" TargetType="Button">
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="Width" Value="200"></Setter>
<Setter Property="Background" Value="{StaticResource BGBrush}"></Setter>
</Style>查看按钮背景是否变为黑色。如果颜色在变化,那么可以尝试厚度之外的其他颜色。
https://stackoverflow.com/questions/30159796
复制相似问题