3

いくつかのボタンと ItemsControl で構成される UserControl があります。このコントロールを使用するウィンドウで、この ItemsControl の ItemTemplate を設定します。

どうすればこれを達成できますか?

ユーザーコントロール:

<UserControl x:Class="WizardTest.WizardControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         x:Name="thisControl"
         Loaded="OnLoaded"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
<DockPanel>
    <UniformGrid DockPanel.Dock="Bottom" Columns="4">
        <Button>Cancel</Button>
        <Button>&lt; Back</Button>
        <Button>Next &gt;</Button>
        <Button>Finish</Button>
    </UniformGrid>
    <ItemsControl DockPanel.Dock="Left" ItemsSource="{Binding WizardPages, ElementName=thisControl}">
    </ItemsControl>
</DockPanel>

窓:

<Window x:Class="WizardTest.EigenesWizardWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WizardTest"
    Title="Wizard Window" Height="300" Width="300">
<local:WizardControl WizardPages="{Binding WizardPages}">

</local:WizardControl>

4

2 に答える 2

1

コントロールに名前を付ける必要があります。

<ItemsControl x:Name="itemsControl" ...

次に、コード ビハインドで、UserControlそれを公開する必要がありますItemTemplate

[BindableAttribute(true)]
public DataTemplate ItemTemplate
{
    get { return this.itemsControl.ItemTemplate; }
    set { this.itemsControl.ItemTemplate = value; }
}

そして最後に、それを使用できます:

<local:WizardControl ...>
    <local:WizardControl.ItemTemplate>
        <DataTemplate>
            ...
于 2013-07-24T09:52:12.977 に答える