WpfリソースからのUI要素の再利用
5489 ワード
私のインタフェースにはいくつかのタブがあります.各タブには次の要素があります.
このコードをXAMLの各タブにコピーすることを避ける方法はありませんか.リソースに上記の要素を一度定義して、各タブがUIリソースを指していますか?答えは肯定的だ.
<StackPanel Orientation="Horizontal"> <Button Content="<" Command="{Binding MoveToPreviousCommand}" /> <Button Content=">" Command="{Binding MoveToNextCommand}" /> </StackPanel>
このコードをXAMLの各タブにコピーすることを避ける方法はありませんか.リソースに上記の要素を一度定義して、各タブがUIリソースを指していますか?答えは肯定的だ.
<Window.Resources> <StackPanel x:Key="Content" Orientation="Horizontal"> <Button Content="<" Command="{Binding MoveToPreviousCommand}" /> <Button Content=">" Command="{Binding MoveToNextCommand}" /> </StackPanel> <DataTemplate x:Key="template1"> <StackPanel Orientation="Horizontal"> <Button Content="<" Command="{Binding MoveToPreviousCommand}" /> <Button Content=">" Command="{Binding MoveToNextCommand}" /> </StackPanel> </DataTemplate> </Window.Resources> <StackPanel> <ContentControl Content="{StaticResource Content}"></ContentControl> <ContentControl Name="contCtrl" ContentTemplate="{StaticResource template1}" Content="This is the content of the content control."/> </StackPanel>