12

標準のControlTemplatesを使用して作成したカスタムスクロールバーを使用していますが、それらをListBoxに適用すると、右下にオーバーライドする方法が見つからないコーナーがあります。

残念ながら、ポイントが増えるまで写真を投稿できません。しかし、私が言及しているコーナーは、垂直スクロールバーと水平スクロールバーの両方が表示されているときに、右下にオフホワイトの色で塗りつぶされたスペースがあり、私はそれを理解することができません

4

3 に答える 3

11

これは、Blendを使用してScrollViewer用に取得したテンプレートコードの一部です。右下隅に長方形を追加し、塗りつぶしを赤に設定しました。同じ方法でスタイルを設定するか、垂直スクロールバー(最初の1つ)の場合はGrid.RowSpan = "2"、水平スクロールバー(2番目の場合)の場合はGrid.ColumnSpan = "2"を使用して、スクロールバーの1つを展開してスペースをカバーできます。

<Style TargetType="{x:Type ScrollViewer}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ScrollViewer}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <ScrollContentPresenter Grid.Column="0"/>
                    <ScrollBar Name="PART_VerticalScrollBar" Grid.Row="0" Grid.Column="1" Value="{TemplateBinding VerticalOffset}" Maximum="{TemplateBinding ScrollableHeight}" ViewportSize="{TemplateBinding ViewportHeight}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
                    <ScrollBar Name="PART_HorizontalScrollBar" Orientation="Horizontal" Grid.Row="1" Grid.Column="0" Value="{TemplateBinding HorizontalOffset}" Maximum="{TemplateBinding ScrollableWidth}" ViewportSize="{TemplateBinding ViewportWidth}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
                    <Rectangle Grid.Row="1" Grid.Column="1" Fill="Red"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
于 2009-12-22T15:08:01.243 に答える
1

別の2つのソリューションが機能します。

1)長方形の色は動的で、キーは「SystemColors.ControlBrushKey」です。このキーは、カスタムスタイル、またはScrollViewerコントロール(またはその祖先の1つ)のリソースでオーバーライドできます。出典:MSDNのこの質問

例 :

<!-- In a style -->
<Style x:Key="MyCustomScrollViewer" TargetType="{x:Type ScrollViewer}">
    <Style.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
    </Style.Resources>
</Style>

<!-- Or in the control -->
<ScrollViewer>
    <ScrollViewer.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
    </ScrollViewer.Resources>
</ScrollViewer>

Rectangle2) 「非表示」の可視性でスタイルを設定します(上記と同じ場所) 。警告:長方形がコントロールの子孫に含まれている場合、これにはサイドエフェクトがあります。

<Style x:Key="MyCustomScrollViewer" TargetType="{x:Type ScrollViewer}">
    <Style.Resources>
        <!-- 'BasedOn' can be omitted -->
        <Style TargetType="Rectangle" BasedOn="{StaticResource {x:Type Rectangle}}">
            <Setter Property="Visibility" Value="Hidden"/>
        </Style>
    </Style.Resources>
</Style>
于 2019-01-21T10:18:05.243 に答える
0

役立つかもしれない2つのこと:

1)Snoopを使用して、アプリケーションの要素ツリーを探索します。これは、問題の発見に役立つ場合があります。

2)コントロールを開始した方法によっては、標準のリストボックスのコピーから開始することを検討する場合があります。空のテンプレートまたは部分的なテンプレートからスタイリングを開始すると、特定のコントロールに問題が見つかりました。

それが役立つことを願っています

于 2009-12-22T07:12:53.437 に答える