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

AcceptsReturn="True" を付ける。

MainWindow.xaml

<Window x:Class="WpfApp17.MainWindow"
        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:local="clr-namespace:WpfApp17"
        mc:Ignorable="d"
        Title="MainWindow" Height="250" Width="400"
        WindowStartupLocation="CenterScreen">

    <Grid>
        <TextBox Grid.Row="0" AcceptsReturn="True" Text="{Binding Text}" />
    </Grid>
</Window>

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

VirtualizingPanel.ScrollUnit="Pixel" を設定する。

MainWindow.xaml

<Window x:Class="WpfApp19.MainWindow"
        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:local="clr-namespace:WpfApp19"
        mc:Ignorable="d"
        Title="MainWindow" Height="250" Width="400">
    <Grid>
        <ListView x:Name="lstView" Margin="30" ItemsSource="{Binding arrayString}" VirtualizingPanel.ScrollUnit="Pixel">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Button Height="50" Width="100" Content="{Binding}"/>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</Window>

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

別スレッドでアイテム追加等を行ったコレクションをBindすると、
「System.NotSupportedException: 'この型の CollectionView は、Dispatcher スレッドとは異なるスレッドからその SourceCollection への変更をサポートしません。’」
というエラーが出る。
CollectionSynchronization にて、参加指定する必要がある。

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

MainWindow.xaml

<Window x:Class="WpfApp17.MainWindow"
        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:local="clr-namespace:WpfApp17"
        mc:Ignorable="d"
        Title="MainWindow" Height="250" Width="400"
        WindowStartupLocation="CenterScreen">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="30"/>
        </Grid.RowDefinitions>

        <TextBox Grid.Row="0" AcceptsReturn="True" Text="{Binding Text}" />
        <Button Grid.Row="1" Content="確認" Click="Button_Click" />
    </Grid>
</Window>

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

MainWindow.xaml

<Window x:Class="WpfApp15.MainWindow"
        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:local="clr-namespace:WpfApp15"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="400">
    <Grid>
        <ListView Margin="30" ItemsSource="{Binding arrayString}">
            
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                </Style>
            </ListView.ItemContainerStyle>

            <ListView.ItemTemplate>
                <DataTemplate>
                    <Button Height="50" Content="{Binding}"/>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</Window>

C#,WPF

今回お借りしたフォント
源真ゴシック (げんしんゴシック) | 自家製フォント工房

プロジェクト

Fontフォルダを作成し、フォントファイルを格納
ビルドアクションはResource
(例としてFontフォルダにしている 他のフォルダ名でもOK)

C#,WPF

UpdateSourceTrigger=PropertyChanged を付けることで、入力後即時反映される。

<TextBox Text="{Binding Url, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="TextChanged">
            <l:LivetCallMethodAction MethodTarget="{Binding}" MethodName="OnURLChanged" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</TextBox>