如何使用此StackPanel作为资源

时间:2012-05-23 17:14:09

标签: .net wpf xaml resourcedictionary

我只是想将StackPanel内容放到ResourceDictionary中。我试着把它包装成数据模板,但没有去。其他一些模板?风格?

如何将其提取到资源,然后在视图的网格布局中使用内容?

干杯,
Berryl

要移动的xaml

<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>

更新

当前模板

<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>

用于视图的另一个StackPanel

        <StackPanel x:Name="_filterByNameOptions" DockPanel.Dock="Left" Orientation="Horizontal" Margin="5, 5" >
            // ... more stuff

            <ContentPresenter Content="{StaticResource FilterTypeByTemplateControl}"/>

        </StackPanel>

enter image description here

最后!

这有效

<ContentPresenter Content="{Binding}" ContentTemplate="{StaticResource FilterTypeByTemplateControl}"/>

enter image description here

1 个答案:

答案 0 :(得分:0)

<ContentControl 
      ContentTemplate="{StaticResource FilterTypeByTemplateControl}" />
相关问题