1

私の WPF アプリケーションには、時間帯に基づいた 2 つの異なるカラー スキーム (デイ モードとナイト モード) が必要です。サードパーティの WPF コントロールで使用されるテンプレートを変更して、さまざまな配色で動作するようにしようとしています。

問題のコントロールは、視覚的な状態を使用して、選択された状態から選択されていない状態への遷移を定義します。

<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="{x:Type Calendar:CalendarButton}">
        <Grid x:Name="LayoutRoot" Background="Transparent">
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="SelectionStates">
                        <VisualState x:Name="Unselected"/>
                        <VisualState x:Name="Selected"/>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
                <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"/>
                <Chromes:ButtonChrome x:Name="SelectionChrome" CornerRadius="1" Margin="2" RenderNormal="False" RenderSelected="{TemplateBinding IsSelected}" RenderFocused="{TemplateBinding IsFocused}" RenderHighlighted="{TemplateBinding IsMouseOver}" />
                <Border x:Name="TodayVisual" BorderThickness="1" CornerRadius="2" Margin="1" Visibility="Collapsed">
                    <Border.BorderBrush>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF282828"/>
                            <GradientStop Color="#FF5F5F5F" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.BorderBrush>
                </Border>
                <ContentPresenter x:Name="Content" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
            </Grid>
        </ControlTemplate>
    </Setter.Value>
</Setter>

表示状態が「選択済み」のときに、コントロールのBackgroundBorderBrush、およびForegroundプロパティを変更する必要があります。ButtonChromeどうすればいいですか?

4

1 に答える 1

1

Chrome 要素を持つほとんどのコントロール (Microsoft のコントロールか他のコントロールか) では、Chrome 要素を削除し、それらを変更する方法が提供されていないことが多いため、手動で再構築する必要があることがわかりました。 (つまり、テンプレートを置き換える方法はありません)。

しかし、他の誰かがより良い方法を持っている場合、私はすべて耳にします。

于 2013-04-22T14:45:01.930 に答える