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>

WPF,デザイン,開発環境

Fluent Designとは

Microsoftが2017年に提唱したデザインシステム。

Windows10の電卓など、一部アプリケーションはすでにFluent Designになっている。
また、Office・カレンダー・メール等、Microsoft製アプリケーションのアイコンデザインがFluent Designベースに変更された。

C#,ソフトウェア開発

正規表現のテストに便利なサイト

IsMatch

string strTarget = @"本日は閉店なり";

if(Regex.IsMatch(strTarget, @"(.+?)は(.+?)なり$"))
{
    Console.WriteLine("IsMatch : Match!!");
}

IsMatch : Match!!

C#,ソフトウェア開発

/// <summary>
/// 使用禁止文字の置換
/// </summary>
/// <param name="strData"></param>
/// <returns></returns>
private static string ReplaceInvalidChar(string strData)
{
    string strResult = strData;

    foreach (char invalidChar in Path.GetInvalidFileNameChars())
    {
        while (strResult.IndexOf(invalidChar) >= 0)
        {
            strResult = strResult.Remove(strResult.IndexOf(invalidChar), 1);
        }
    }

    List<string> arrayReplaceChar = new List<string> { "*", "/", "&", """, "\", "
", "
", "	", "<", ">", "[", "]", "{", "}", "|", ":", ";", "?", "!", ",", ".", "=", "~", "$", "%" };

    foreach (string strReplaceChar in arrayReplaceChar)
    {
        strResult = strResult.Replace(strReplaceChar, "");
        strResult = strResult.Replace(Strings.StrConv(strReplaceChar, VbStrConv.Wide), "");
    }

    strResult = strResult.Trim(' ');

    return strResult;
}

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

MainView.xaml

<Window x:Class="WpfApp27.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:WpfApp27.View"
        xmlns:vm="clr-namespace:WpfApp27.ViewModel"
        mc:Ignorable="d"
        Title="MainView" Height="250" Width="400">

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

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <StackPanel Grid.Column="0">
            <Button Content="Page1へ">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <l:LivetCallMethodAction MethodTarget="{Binding}" MethodName="ScrollToObject" MethodParameter="{Binding ElementName=page1}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
            <Button Content="Page2へ">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <l:LivetCallMethodAction MethodTarget="{Binding}" MethodName="ScrollToObject" MethodParameter="{Binding ElementName=page2}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
            <Button Content="Page3へ">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <l:LivetCallMethodAction MethodTarget="{Binding}" MethodName="ScrollToObject" MethodParameter="{Binding ElementName=page3}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
        </StackPanel>

        <ScrollViewer Grid.Column="1">
            <StackPanel>
                <StackPanel.Resources>
                    <Style TargetType="TextBlock">
                        <Setter Property="Margin" Value="0,0,0,300"/>
                    </Style>
                </StackPanel.Resources>
                
                <TextBlock x:Name="page1" Text="Page1"/>
                <TextBlock x:Name="page2" Text="Page2"/>
                <TextBlock x:Name="page3" Text="Page3"/>
            </StackPanel>
        </ScrollViewer>
    </Grid>
    
</Window>

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

Resources.resx

アクセス修飾子をPublicにし、文字列を格納する。