WPFのBindingで質問です。
Q1)Bindingの対象は別のclassのPropertyなのにどうしてFullpathだけでClass名を付けずに呼べるのか?
Q2)textBoxにはXAMLでBindingを設定(Text="{Binding Fullpath}")しているのになぜC#でもDataContentに設定しなければならないのか?
Q3)この変数はなくせないのか?
Q4)valueはどこから出てきたの?
以上4点、よろしくお願いします。
/// <TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="27,90,0,0" TextWrapping="Wrap" Text="{Binding Fullpath}" VerticalAlignment="Top" Width="444"/>
// Q1)Bindingの対象は別のclassのPropertyなのにどうしてFullpathだけでClass名を付けずに呼べるのか?
using System.Windows;
namespace WpfApplication1
{
using System;
using System.ComponentModel;
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); path.Fullpath = "test01"; textBox.DataContext = path;
// Q2)textBoxにはXAMLでBindingを設定(Text="{Binding Fullpath}")しているのになぜC#でもDataContentに設定しなければならないのか?
}
private Path path = new Path(); private void button_Click(object sender, RoutedEventArgs e) { System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog(); System.Windows.Forms.DialogResult result = folderDialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { string folderFullPath = folderDialog.SelectedPath; path.Fullpath = folderFullPath; } } } internal class Path : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; private string fullpath;//Q3)この変数はなくせないのか? public string Fullpath { get { return fullpath; } set { fullpath = value;//Q4)valueはどこから出てきたの? NotifiyPropertyChanged("Fullpath"); } } private void NotifiyPropertyChanged(String propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } }
}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/07/08 07:32