C#,WPF,ソフトウェア開発

画像の登録

1. プロジェクトのプロパティ → リソース → イメージ に、表示したい画像を登録する。

C#,WPF,ソフトウェア開発

MainView.xaml

<Window x:Class="WpfApp15.View.MainView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
        xmlns:l="http://schemas.livet-mvvm.net/2011/wpf"
        xmlns:local="clr-namespace:WpfApp15.View"
        xmlns:vm="clr-namespace:WpfApp15.ViewModel"
        mc:Ignorable="d"
        Title="MainView" Height="450" Width="800">

    <Window.DataContext>
        <vm:MainViewModel/>
    </Window.DataContext>

    <i:Interaction.Triggers>
        <i:EventTrigger EventName ="Loaded">
            <l:LivetCallMethodAction MethodTarget="{Binding}" MethodName="OnLoaded" />
        </i:EventTrigger>
    </i:Interaction.Triggers>

    <Grid>
        <Button>
            <Button.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="MenuParent" ItemsSource="{Binding ArrayMenu1}">
                        <MenuItem.ItemContainerStyle>
                            <Style TargetType="MenuItem">
                                <Setter Property="Header" Value="{Binding DisplayName}"/>
                                <Setter Property="IsChecked" Value="{Binding Checked}"/>
                                <Setter Property="Command" Value="{Binding}"/>
                            </Style>
                        </MenuItem.ItemContainerStyle>
                    </MenuItem>
                </ContextMenu>
            </Button.ContextMenu>
        </Button>
    </Grid>
</Window>