|
2 ماه پیش | |
---|---|---|
WpfApp1 | 2 ماه پیش | |
README.md | 2 ماه پیش | |
WpfApp1.sln | 2 ماه پیش | |
img1.png | 2 ماه پیش | |
Снимок экрана 2024-04-26 104424.png | 2 ماه پیش | |
Снимок экрана 2024-04-26 105726.png | 2 ماه پیش | |
Снимок экрана 2024-04-26 110338.png | 2 ماه پیش |
xml
<TextBox
x:Name="myTextBox"
Height="30" />
<TextBlock
x:Name="myTextBlock"
Text="{Binding
ElementName=myTextBox,
Path=Text}"
Height="30" />
</StackPanel>
csharp
namespace WpfApp1 {
public partial class MainWindow : Window
{
public MainWindow() {
InitializeComponent();
Binding binding = new Binding();
// ýëåìåíò-èñòî÷íèê
binding.ElementName = "myTextBox";
// ñâîéñòâî ýëåìåíòà-èñòî÷íèêà
binding.Path = new PropertyPath("Text");
// óñòàíîâêà ïðèâÿçêè äëÿ ýëåìåíòà-ïðèåìíèêà
myTextBlock.SetBinding(TextBlock.TextProperty, binding);
}
}
}
xml
<local:Phone
x:Key="nexusPhone"
Title="Nexus X5"
Company="Google"
Price="25000" />
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock
Text="Ìîäåëü:"
Foreground="White"/>
<TextBlock
x:Name="titleTextBlock"
Text="{Binding
Source={StaticResource nexusPhone},
Path=Title}"
Foreground="White"
Grid.Column="1"/>
<TextBlock
Text="Öåíà:"
Foreground="White"
Grid.Row="1"/>
<TextBlock
x:Name="priceTextBlock"
Text="{Binding
Source={StaticResource nexusPhone},
Path=Price}"
Foreground="White"
Grid.Column="1"
Grid.Row="1"/>
csharp
namespace WpfApp1 {
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
class Phone
{
public string Title { get; set; }
public string Company { get; set; }
public int Price { get; set; }
}
}
xml
<local:Phone
x:Key="nexusPhone"
Company="Google"
Price="25000" />
<TextBlock
x:Name="titleTextBlock"
Text="{Binding
Source={StaticResource nexusPhone},
Path=Title,
TargetNullValue=Òåêñò ïî óìîë÷àíèþ}" />
xml
<TextBlock
Foreground="Black"
Text="{Binding
RelativeSource={RelativeSource
Mode=FindAncestor,
AncestorType={x:Type Grid}},
Path=Background}" />
</Grid>
<local:Phone
x:Key="nexusPhone"
Title="Nexus X5"
Company="Google"
Price="25000" />
</Window.Resources>
<Grid
DataContext="{StaticResource nexusPhone}"
<Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <TextBlock Text="Ìîäåëü" /> <TextBlock Text="{Binding Title}" Grid.Row="1" /> <TextBlock Text="Ïðîèçâîäèòåëü" Grid.Column="1"/> <TextBlock Text="{Binding Company}" Grid.Column="1" Grid.Row="1" /> <TextBlock Text="Öåíà" Grid.Column="2" /> <TextBlock Text="{Binding Price}" Grid.Column="2" Grid.Row="1" /> </Grid>
# Интерфейс INotifyPropertyChanged
<local:Phone
x:Key="nexusPhone"
Title="Nexus X5"
Company="Google"
Price="25000" />
</Window.Resources>
<Grid>
<TextBlock
Text="{Binding
StringFormat=Èòîãîâàÿ öåíà {0} ðóáëåé,
Source={StaticResource nexusPhone},
Path=Price}" />
</Grid>