簡體   English   中英

wpf屬性繼承

[英]wpf property inheritance

我想問一個關於該代碼的簡單XAML代碼的問題,如下所示。

<Window x:Class="WpfApplication15.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" Background="Orange" FontStyle="Italic">
<StackPanel>
    <Label>blo</Label>
    <Button>hi</Button>
    <Button>hi2</Button>
</StackPanel>
</Window>

因此,我們可以簡單地想象一下,將背景標記為橙色,但是將按鈕的背景色設為橙色將作為默認值,但是所有控件FontStyle將變為斜體,所以問題就在於此! 為什么在根目錄下所有控件的字體樣式都會影響到按鈕的背景卻沒有?

我想按鈕的ControlTemplate相對於Windows ui指南明確地設置了背景畫筆。 因此, Control.BackgroundProperty屬性繼承被破壞了。

為了證明這一點,也許這個工具會有所幫助。

這是默認按鈕模板的定義,Microsoft_Windows_Themes:ButtonChrome可以解決問題

                    <ControlTemplate TargetType="{x:Type Button}">
                    <Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" RenderDefaulted="{TemplateBinding IsDefaulted}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}">
                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" RecognizesAccessKey="True"/>
                    </Microsoft_Windows_Themes:ButtonChrome>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM