0

各ユーザー コントロールを TabItem に含めるために、TabControl をユーザー コントロールにバインドしたいと思います。

TabControl 自体が UserControl にあることを知っていれば、これは可能ですか?

UserControl の Dependency プロパティは次のとおりです。

public IList<UserControl> ListUserControls
    {
        get { return (IList<UserControl>)GetValue(ListUserControlsProperty); }
        set { SetValue(ListUserControlsProperty, value); }
    }

    // Using a DependencyProperty as the backing store for ListUserControls.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty ListUserControlsProperty =
        DependencyProperty.Register("ListUserControls", typeof(IList<UserControl>), typeof(NavigationPane), new PropertyMetadata(new List<UserControl>()));

MainWindow で UserControl は次のとおりです。

<pyRGC:NavigationPane.ListUserControls>
    <pyRGCTest:UC_1 />
</pyRGC:NavigationPane.ListUserControls>

これをコーディングすると、「次のタイプが予期されていました: "IList'1"」と表示されます。XAML で IList を使用する方法がわかりません。

どのようにできるのか ?

ありがとう

4

1 に答える 1

-1

一定数のタブを表示したいのに を使用していないため、ではなく でアイテムMVVMを提供する必要があります。TabControlXAMLBinding

サンプルコードは以下のとおりです。

<TabControl>
    <TabControl.Items>
        <TabItem Header="Tab One">
            <local:UserControl1 />
        </TabItem>

        <TabItem Header="Tab Two">
            <local:UserControl2 />
        </TabItem>
    </TabControl.Items>
</TabControl>
于 2013-04-24T08:15:23.737 に答える