2012-05-23 44 views
3

我只是想将StackPanel内容放入ResourceDictionary中。我试图把它包装成一个数据临时表,但没有去。其他一些模板?风格?如何使用此StackPanel作为资源

我怎样才能提取这个资源,然后在我的视图的网格布局中使用内容?

干杯,
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> 

UPDATE

当前模板

<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

+0

为什么你不能使用数据模板? –

+0

@WallstreetProgrammer。之前我得到一个错误,可能是因为该项目需要构建。但是现在我正在做一些其他的傻事 - 从我的更新后的帖子看到,而不是堆栈面板显示,我得到它的ToString()。我需要加强我的模板技能! – Berryl

+0

@WallstreetProgrammer。好的,我有一些工作按照最后编辑在后。让我知道是否有什么我可以做得更好,最好是作为答案,所以我可以关闭它,并留下面包碎片forr别人与DataTemplate学习问题! – Berryl

回答

0
<ContentControl 
     ContentTemplate="{StaticResource FilterTypeByTemplateControl}" /> 
+0

真棒和thks! – Berryl

+0

这将丢失资源内的绑定(本例中为ShowAllContacts)。它需要是: kevinpo