-1

ボタンとトグルボタンをホストする必要があるアプリケーション内の ToolbarTray に wpf ツールバーがあります。誰かがMVVMでこの動作を実装する方法を提案できますか? 以下のコードは私が今持っているものです:

 <ToolBarTray Margin="5,30,5,30" MinWidth="35" HorizontalAlignment="Center" Orientation="Vertical" Background="Transparent">
            <ToolBar x:Name="ToolBarControl" HorizontalAlignment="Stretch" ItemsSource="{Binding ToolBarItems}" >
                <ToolBar.ItemTemplate>
                    <DataTemplate>
                        <Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" HorizontalAlignment="Stretch" Margin="0,0,0,15"
                        Template="{Binding ToolBarIcon}" 
                        cal:Message.Attach="[Event Click] = [Action Select()]"
                        IsEnabled="True"
                        ToolTip="{Binding Text}"/>
                    </DataTemplate>
                </ToolBar.ItemTemplate>
            </ToolBar>
        </ToolBarTray>

Button は通常の Button または ToggleButton です。前もって感謝します。

4

1 に答える 1

0

MVVM パターンでは、モデル クラスには、バインドしてビューに表示するプロパティ (すべてのデータ オブジェクト) が含まれます。したがって、ToolBarItems コレクションはモデルの一部になります。

ビューには基本的に、作成した上記のコードが含まれます。また、コード ビハインド ファイルには、モデル クラス型のオブジェクトがプロパティとして存在します。

ビューモデルは、モデルとビュー オブジェクトを初期化し、モデルをビューのデータ コンテキストにバインドできます。

于 2012-08-28T10:11:26.760 に答える