にコントロールTabControl
付きがあります。あるタブにテキストを入力して別のタブに切り替えると、元のタブに戻ったときに元のタブの元に戻す履歴が消えています。TextBox
ContentTemplate
発生する別の問題は、選択されたテキストの選択が解除され、キャレットが の先頭に移動することTextBox
です。
ハードコーディングされTabItem
たコントロールだけでウィンドウを作成すると、元に戻す履歴が保持されます。この問題は、バインディングまたはテンプレートに関係しています。
メイン ウィンドウの XAML は次のとおりです。
<Window x:Class="TabbedTextAreaTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button Command="{Binding AddNewTab}">Add Tab</Button>
<TabControl ItemsSource="{Binding Tabs}" Grid.Row="1">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Header}"/>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<TextBox Text="{Binding Content, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
</Grid>
</Window>
これらのコマンドを手動でキャッチせずにタブを切り替えるときに、元に戻す/やり直しの履歴と選択したテキストを保存する方法はありますか?