问题
I am just trying to get the StackPanel content into a ResourceDictionary. I tried wrapping it into a data tempplate but no go. Some other sort of template? A style?
How can I extract this to a resource and then use the content in my view's grid layout?
Cheers,
Berryl
the xaml to move
<StackPanel x:Name="_filterByTypeOptions" Orientation="Horizontal" Margin="5, 5" >
<RadioButton Style="{StaticResource FilterPanelRadioButtonStyle}"
IsChecked="{Binding ShowAllContacts, Mode=TwoWay}"
Content="{resx:Resx Filter_ByType_ShowAll}" ToolTip="{Resx Filter_ByType_ShowAll_ToolTip}"
/>
// ... more of the same
</StackPanel>
UPDATE
current template
<DataTemplate x:Key="FilterTypeByTemplateControl">
<StackPanel x:Name="_filterByTypeOptions" Orientation="Horizontal" Margin="5, 5" >
<RadioButton Style="{StaticResource FilterPanelRadioButtonStyle}"
IsChecked="{Binding ShowAllContacts, Mode=TwoWay}"
Content="{resx:Resx Filter_ByType_ShowAll}" ToolTip="{Resx Filter_ByType_ShowAll_ToolTip}"
/>
/// etc.
</StackPanel>
</DataTemplate>
used in another StackPanel of the view
<StackPanel x:Name="_filterByNameOptions" DockPanel.Dock="Left" Orientation="Horizontal" Margin="5, 5" >
// ... more stuff
<ContentPresenter Content="{StaticResource FilterTypeByTemplateControl}"/>
</StackPanel>

finally!
This works
<ContentPresenter Content="{Binding}" ContentTemplate="{StaticResource FilterTypeByTemplateControl}"/>

回答1:
<ContentControl
ContentTemplate="{StaticResource FilterTypeByTemplateControl}" />
来源:https://stackoverflow.com/questions/10724770/how-to-use-this-stackpanel-as-a-resource