新しいWPFでは、単純なテキストボックスバインディングを実装しようとしています。これを実行するにはいくつかの助けが必要です。cの別のクラスからのwpfのテキストボックスからのデータバインディング
XAML
<Window x:Class="WPFModel.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:src="clr-namespace:WPFModel"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<src:Test x:Key="myDataSource" TextBoxName="Text Init" />
</Window.Resources>
<Grid>
<TextBox x:Name="S1" Text = "{Binding Source={StaticResource myDataSource}, Path=TextBoxName, UpdateSourceTrigger= PropertyChanged, Mode = TwoWay}" HorizontalAlignment="Left" Height="50" Margin="160,165,0,0" VerticalAlignment="Top" Width="185"/>
</Grid>
メインウィンドウ
namespace WPFModel
{
public partial class MainWindow : Window
{
Test tb = new Test();
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
tb.Drawtext();
}
}
}
コードビハインド
FYI:デバッガの[出力]ウィンドウに、バインディングエラーが発生したことを示すWPFのエラーメッセージが表示されます。そこを見ていたら、バインディングが失敗した理由を正確に説明するエラーメッセージが表示されます。 –