0

I have a WPF WebBrowser control beside a WPF TreeView control. Both have default styles with default properties. I have not changed anything except placing them on my WPF window. If you view the screen shot below you can see the two controls have two different scroll bars. I have no idea why this is happening.

Is there a way to make one control's scroll bar look like the other, or just default them both to windows styles?

Thanks

enter image description here

4

3 に答える 3

1

あなたのコメントに答えるには:

そのテーマをリソースに保持し(リボンコントロールがそれを使用します)、そのツリービューコントロールからスクロールバーテーマを削除する方法はありますか?– LandinMartens6月23日19:49

はい。

オプション1

次のように、コントロールのデフォルトスタイルをオーバーライドできます。

<Style TargetType="{x:Type TreeView}">
  ...
</Style>

これにより、すべてのTreeViewコントロールのスタイルが変更されます(スタイルがApp.xamlディクショナリで定義されていると想定)。いくつかのコントロールのスタイルのみをオーバーライドする場合は、次の名前を付けることができます。

<Style x:Key="XTreeViewStyle"
       TargetType="{x:Type TreeView}">
  ...
</Style>

そして、それらのコントロールのスタイルを明示的に設定します(<TreeView Style="{StaticResource XTreeViewStyle}"/>)。または、グリッドなどの特定のコンテキスト内でスタイルを作成できます(したがって、グリッド内のこれらのコントロールにのみ影響します)。

<Grid>
  <Grid.Resources>
    <Style TargetType="{x:Type TreeView}">
    </Style>
  </Grid.Resources>
</Grid>

スクロールバーをオーバーライドしているスタイルは、特にTreeViewをターゲットにしていないと思います...おそらくTreeViewが継承するコントロールをターゲットにしています。したがって、TreeView、ItemsControl、Control、FrameworkElement、またはUIElementを対象とするデフォルトのスタイルを探します。見つけたら、名前を付けるか、スタイルをより限定されたコンテキストに移動します。

たとえば、スタイルはおそらく次のように設定されています。

<Style TargetType="{x:Type ItemsControl}">
  ...
</Style>

<Style TargetType="{x:Type Ribbon}">
  <Style.Template>
    <ControlTemplate>
      <ItemsControl>
        ...
      </ItemsControl>
    </ControlTemplate>
  </Style.Template>
</Style>

ItemsControlスタイルがリボンにのみ影響するようにするには、ItemsControlスタイルをリボンのテンプレートに移動します。

<Style TargetType="{x:Type Ribbon}">
  <Style.Template>
    <ControlTemplate>
      <ControlTemplate.Resources>
        <Style TargetType="{x:Type ItemsControl}">
          ...
        </Style>
      </ControlTemplate.Resources>
      <ItemsControl>
        ...
      </ItemsControl>
    </ControlTemplate>
  </Style.Template>
</Style>

ただし、正確なアプローチは、スタイルがどの程度正確に設定されているかによって異なり、これは私が提案したよりもはるかに複雑になる可能性があります。たとえば、すべてがそのItemsControlスタイルを使用する必要があるいくつかの異なるスタイルがある場合、次のような名前付けと継承を使用できます。

<Style TargetType="{x:Type ItemsControl}"
       x:Key="XItemsControlStyle">
  ...
</Style>

<Style TargetType="{x:Type Ribbon}">
  <Style.Template>
    <ControlTemplate>
      <ControlTemplate.Resources>
        <Style TargetType="{x:Type ItemsControl}"
               BasedOn="{StaticResource XItemsControlStyle}">
          ...
        </Style>
      </ControlTemplate.Resources>
      <ItemsControl>
        ...
      </ItemsControl>
    </ControlTemplate>
  </Style.Template>
</Style>

<Style TargetType="{x:Type RibbonItem}">
  <Style.Template>
    <ControlTemplate>
      <ControlTemplate.Resources>
        <Style TargetType="{x:Type ItemsControl}"
               BasedOn="{StaticResource XItemsControlStyle}">
          ...
        </Style>
      </ControlTemplate.Resources>
      <ItemsControl>
        ...
      </ItemsControl>
    </ControlTemplate>
  </Style.Template>
</Style>

オプション2

TreeViewのスタイルを明示的に設定します。これは、TreeView(または少なくとも使用するもの)の元のスタイルを決定し、それに名前を付けてから、スタイルを設定するTreeViewに明示的に設定することを意味します。(これを行う方法については、オプション2を参照してください)

これらのリンクはデフォルトのスタイルを提供すると思います。

于 2012-07-02T19:56:04.450 に答える
0

アプリケーションリソースにカスタムテーマがあるようです。はテーマのスタイルを使用しません。これWebBrowserはWPFコントロールではなく、Win32コントロールの単なるラッパーであるためです。したがって、WebBrowserのスクロールバーを左側のように表示することはできません。カスタムスタイルを削除したい場合は、リソースから削除する必要があります。

于 2012-06-23T19:36:14.150 に答える
0

WebBrowser is just a wrapper around native component and it's really hard to deal with that in WPF. I had a lot of pain with it in my projects.

So, it can be good idea to try Chromium for WPF from CodePlex. It is much more flexible.

于 2012-06-23T20:05:09.013 に答える