1

TextBoxたとえば、 「TextBoxStyleBase」のデフォルト スタイルがあるとします。次に、別の境界線の色を定義して、Base-styleDataGridという独自のTextBoxスタイル BasedOn を持つスタイルを定義します。

a 内のどこかでDataGrid別のスタイルを定義したいのですTextBoxが、style で定義されたものから継承しDataGridます。

現在の「コンテキスト」内の特定のコントロールに対して現在定義されているスタイルからスタイルを継承させる方法はありますか?

編集:

より明確にするために、ここに私が持っているものがあります:

<!-- explicit style for all TextBoxes -->
<Style TargetType="{x:Type TextBox}" x:Key="TextStyle">
    <Setter Property="FontSize" Value="16"/>
</Style>

<!-- implicit style for all TextBoxes -->
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextStyle}"/>

<!-- DataGrid style changing inner TextBox style -->
<Style TargetType="{x:Type DataGrid}">
    <Style.Resources>
        <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextStyle}">
            <Setter Property="FontSize" Value="20"/>
        </Style>
        <!-- since TextBox has defined implicit style this would be equivalent to -->
        <!--<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
            <Setter Property="FontSize" Value="20"/>
        </Style>-->
    </Style.Resources>
</Style>

<Control>
    <DataGrid>
        <Row>
            <TextBox/> <!-- should show as defined in DataGrid style -->
        </Row>
        <Row>
            <Row.Resources>
                <Style TargetType="{x:Type TextBox}" BasedOn=" ??? ">
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="FontWeight" Value="Bold"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Row.Resources>
            <TextBox/> <!-- should show with additional trigger -->
        </Row>
    </DataGrid>
</Control>

BasedOn = '???' に何を入れるか テキストは FontSize 20 で表示されますが、ホバーすると太字になります。

4

2 に答える 2

0

データグリッド内のテキストボックスには次を使用してください。

<Style TargetType="TextBox" BasedOn="{StaticResource <your style name>}">

PS: あなたの場合は TextBoxStyleBase になります。

于 2017-05-19T08:53:25.163 に答える