2017-08-09 13 views
-1

私はControltemplateでカスタムエキスパンダーを作成しようとしていません。私の最初の質問は、Expanderの内容をどこに置くことができるか(Expanderに表示されているテキストではなく、Expanderをクリックすると表示される内容です)(WPF)どのようにしてExpander-Controltemplateにコンテンツを埋め込むことができますか?

これがApp.xamlの私のコードです:

<Application.Resources> 

     <ControlTemplate x:Key="FileExpanderButton" TargetType="{x:Type ToggleButton}"> 
      <Image Name="BrowseUsedFiles" Source="F:\AudioNodeGUI_XAML\images\Browse_used_files.jpg"> 

      </Image> 
     </ControlTemplate> 

     <ControlTemplate x:Key="FileExpander" TargetType="{x:Type Expander}"> 
      <DockPanel> 
       <ToggleButton x:Name="ExpanderButton" Template="{StaticResource FileExpanderButton}" OverridesDefaultStyle="True" DockPanel.Dock="Top"/> 
       <ContentPresenter x:Name="ExpanderContent" 
          Visibility="Collapsed" 
          Content="{TemplateBinding Content}" 
          DockPanel.Dock="Bottom" /> 
      </DockPanel> 
      <ControlTemplate.Triggers> 
       <Trigger Property="IsExpanded" Value="True"> 
        <Setter TargetName="ExpanderContent" 

       Property="Visibility" Value="Visible"/> 
       </Trigger> 
      </ControlTemplate.Triggers> 
     </ControlTemplate> 

    </Application.Resources> 
</Application> 

そして、別の質問:正確のContentPresenterは何でしょうか?私は単にそれを私のコンテンツに置き換えることはできますか?

+0

コンテンツを提示するのは、コンテンツプレゼンターです。 ExpanderのIsExpandedプロパティをtrueに設定すると機能します。 – mm8

+0

ContentPresenterでは、TemplateBindingを使わずにmain.xamlファイルに入力できます。

+0

私はそうは思わない私はあなたの質問を理解しています。しかし、はい、カスタムスタイルを使用するエキスパンダーを作成する必要があります。 – mm8

答えて

0

Expanderはコンテンツ(他のXAML)が含まれていることを意味しますが、その内容はコントロールテンプレートで定義されていないため、コントロールを使用しているユーザーによって定義されます。

ContentPresenterは、あなたが行っているように、そのコンテンツを表示するためにコントロールテンプレート内で使用されます。

関連する問題