neda mpr
شنبه 08 شهریور 1393, 12:37 عصر
سلام
میخواستم بپرسم چطور میشه یک Property رو که توی کد نوشته شده است رو به property یک کنترل bind کرد. مثلا من توی فرم اصلی یه property از نوع string دارم؛ میخوام این property بایند بشه به پروپرتی Text یک textBox
اگه میشه با C# راهنمایی کنید. مرسی :لبخندساده:
یاسردرا
شنبه 08 شهریور 1393, 14:13 عصر
<Window x:Class="WpfApplication7.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>
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="96,155,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
<TextBox Text="{Binding s}" Height="23" HorizontalAlignment="Left" Margin="286,97,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" />
</Grid>
</Window>
namespace WpfApplication7
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
string _s = "yaser";
public string s { get { return _s; } set { _s = value; } }
public MainWindow()
{
InitializeComponent();
DataContext = this;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(_s);
}
}
}
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.