###前提・実現したいこと
WindowsフォームアプリケーションからWPFアプリケーション(DLL)を呼び出してデータをバインドしようとしているのですが、例外が発生してしまいます。
例外が発生する箇所は下記ソースコードWpfApplicationのWindow_Loaded()内の「xow.WriteNode(xxr);」です。
いろいろ調べておりますが、解決策が見つからず困っております。
もしおわかりの方がおられましたら、ご教授いただけると幸いです。
何卒、よろしくお願い申し上げます。
###発生している問題・エラーメッセージ
'System.Windows.Markup.XamlParseException' の初回例外が PresentationFramework.dll で発生しました。 追加情報: 型 'TextBox' の 'Text' プロパティで 'Binding' を設定することはできません。'Binding' は、DependencyObject の DependencyProperty でのみ設定できます。
###該当のソースコード
ClassLibrary
C#
1namespace ClassLibrary1 2{ 3 public class Class1 4 { 5 public string name { get; set; } 6 } 7}
WpfApplication
C#
1namespace WpfApplication1 2{ 3 public partial class MainWindow : Window 4 { 5 public ClassLibrary1.Class1 obj { get; set; } 6 7 public MainWindow() 8 { 9 InitializeComponent(); 10 } 11 12 private void Window_Loaded(object sender, RoutedEventArgs e) 13 { 14 this.pageGrid.DataContext = obj; 15 XamlXmlReader xxr = new XamlXmlReader("UserControl.xaml"); 16 XamlObjectWriter xow = new XamlObjectWriter(xxr.SchemaContext); 17 while (xxr.Read()) 18 { 19 xow.WriteNode(xxr); 20 } 21 this.pageGrid.Children.Add((UIElement)xow.Result); 22 } 23 } 24}
XAML(MainWindow.xaml)
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="400" Width="525" Loaded="Window_Loaded"> <Grid> <Grid Name="pageGrid" /> </Grid> </Window>
XAML(UserControl.xaml)
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Grid Height="300" Width="400"> <TextBox Text="{Binding name}" /> </Grid> </UserControl>
WindowsFormsApplication
C#
1namespace WindowsFormsApplication1 2{ 3 public partial class Form1 : Form 4 { 5 public Form1() 6 { 7 InitializeComponent(); 8 } 9 10 private void button1_Click(object sender, EventArgs e) 11 { 12 ClassLibrary1.Class1 obj = new ClassLibrary1.Class1(); 13 obj.name = this.textBox1.Text; 14 15 var window = new WpfApplication1.MainWindow(); 16 ElementHost.EnableModelessKeyboardInterop(window); 17 window.obj = obj; 18 window.ShowDialog(); 19 } 20 } 21}
###補足情報(言語/FW/ツール等のバージョンなど)
OS:Windows7 64bit
FW:.NET Framework 4 Client Profile
IDE:Visual Studio 2010
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/23 03:02