-1
我不想用Controltemplate創建自定義擴展器。我的第一個問題是:我在哪裏可以放置擴展器的內容(而不是擴展器上顯示的文本,如果點擊擴展器則顯示內容)?(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?我可以用我的內容簡單替換嗎?
它是呈現內容的ContentPresenter。如果將Expander的IsExpanded屬性設置爲true,它應該可以工作。 – mm8
因此,使用ContentPresenter但沒有Templatebinding,我可以在main.xaml文件中輸入: –
Ben
我不認爲我理解你的問題。但是,是的,您需要創建一個使用您的自定義樣式的擴展器。 – mm8