如何使用本的StackPanel作为一个资源作为一个、如何使用、资源、StackPanel

2023-09-05 04:40:09 作者:社会不惯人

我只是想获得的StackPanel内容转换为ResourceDictionary中。我试着包成一个数据tempplate,但没有去。一些其他种类的模板?样式?

我如何提取这一个资源,然后用在我看来的网格布局的内容?

干杯, Berryl

XAML中移动

 < StackPanel的X:名称=_ filterByTypeOptions方向=横向保证金=5,5>
    <单选按钮样式={的StaticResource FilterPanelRadioButtonStyle}
         =器isChecked{结合ShowAllContacts,模式=双向}
         内容={RESX:的Resx Filter_ByType_ShowAll}工具提示={的Resx Filter_ByType_ShowAll_ToolTip}
         />
    // ...更多相同

< / StackPanel的>
 

更新

当前模板

 < D​​ataTemplate中X:关键=FilterTypeByTemplateControl>
    < StackPanel的X:名称=_ filterByTypeOptions方向=横向保证金=5,5>
        <单选按钮样式={的StaticResource FilterPanelRadioButtonStyle}
                     =器isChecked{结合ShowAllContacts,模式=双向}
                     内容={RESX:的Resx Filter_ByType_ShowAll}工具提示={的Resx Filter_ByType_ShowAll_ToolTip}
                     />
        /// 等等。
    < / StackPanel的>
< / DataTemplate中>
 

视图中的另一个的StackPanel使用

 < StackPanel的X:名称=_ filterByNameOptionsDockPanel.Dock =左倾角度=水平保证金=5,5>
            // ...更多的东西

            <内容presenter CONTENT ={的StaticResource FilterTypeByTemplateControl}/>

        < / StackPanel的>
 
StackPanel跟Grid在布局中的使用

终于来了!

本作品

 <内容presenter CONTENT ={结合}的ContentTemplate ={的StaticResource FilterTypeByTemplateControl}/>
 

解决方案

 < ContentControl中
      的ContentTemplate ={的StaticResource FilterTypeByTemplateControl}/>
 

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}"/>

解决方案

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