4

我只是想将 StackPanel 内容放入 ResourceDictionary。我尝试将其包装到数据模板中,但没有成功。其他类型的模板?一种风格?

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

干杯,
贝里尔

要移动的 xml

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

在此处输入图像描述

最后!

这有效

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

在此处输入图像描述

4

1 回答 1

0
<ContentControl 
      ContentTemplate="{StaticResource FilterTypeByTemplateControl}" />
于 2012-05-23T19:16:44.430 回答