[英]I can not apply the Style for custom UserControl
我無法將樣式應用於自定義UserControl 。 TextBlock和MyControl的樣式在同一詞典中。 TextBlock的樣式使用沒有問題。 但是對於MyControl樣式則不適用。 為什么?
// XAML xmlns:local="clr-namespace:MyControlNameSpace" <Grid> <TextBlock x:Name="text" Style="{DynamicResource TextStyle}"/> <local:MyControl x:Name="control" Style="{DynamicResource ControlStyle}"/> </Grid> // RESOURCE DICTIONARY <Style x:Key="ControlStyle" TargetType="{x:Type local:MyControl}"> <Setter Property="Height" Value="Auto"/> <Setter Property="Width" Value="Auto"/> <Setter Property="Foreground" Value="White"/> <Setter Property="ColorMain" Value="Black"/> <Setter Property="Margin" Value="2"/> </Style> <Style x:Key="TextStyle" TargetType="{x:Type TextBlock}"> .... <Setter Property="FontSize" Value="32"/> ... </Style>
//PART of CS
public partial class MyControl: UserControl { .... }
嘗試改變
<Setter Property="ColorMain" Value="Black"/>
至
<Setter Property="Background" Value="Black"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.