Ich schrieb eine einfache Silverlight-Anwendung. Meine Stile werden zur Entwurfszeit korrekt angezeigt, aber wenn ich versuche, die Anwendung auszuführen, werden alle Stile in Ressourcenwörterbuchdateien, die in der app.xaml-Datei zusammengeführt werden, zur Laufzeit nicht auf ein Steuerelement angewendet.Was könnte verhindern, dass Stile zur Laufzeit auf ein Silverlight-Steuerelement angewendet werden?
Eigentlich scheinen nur UserControl
Stile nicht zu gelten. Aber der Rest funktioniert (wie die Button
auf der Seite). Was könnte dieses Problem verursachen und wie kann ich es beheben?
Mein Code ist so etwas wie dieses:
Styles.xaml:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="UserControl">
<Setter Property="FlowDirection" Value="RightToLeft" />
<Setter Property="FontFamily" Value="Tahoma" />
<Setter Property="Background" Value="Aqua" />
</Style>
<Style TargetType="Button" >
<Setter Property="Background" Value="Aqua" />
</Style>
</ResourceDictionary>
App.xaml:
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Silverlight.Test._01.App"
>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
MainPage.xaml:
<UserControl x:Class="Silverlight.Test._01.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
<Grid x:Name="LayoutRoot" Background="White">
<Button Content="This is a test" Height="23" HorizontalAlignment="Left" Margin="12,12,0,0" Name="button1" VerticalAlignment="Top" Width="220" />
<sdk:Label Height="28" HorizontalAlignment="Left" Margin="12,6,0,0" Name="label1" VerticalAlignment="Top" Width="351" Content="Test label" />
</Grid>
</UserControl>
Wenn Sie uns mitteilen, dass Sie diese Frage zuvor ohne Ergebnisse gestellt haben, ist dies nur hilfreich, wenn Sie uns ausdrücklich mitteilen, was die vorherigen Vorschläge waren und warum sie nicht für Sie funktionierten. –