30 lines
910 B
C#
30 lines
910 B
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
|
|
namespace WPF绑定元素_2_代码检索绑定;
|
|
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
var binding = BindingOperations.GetBinding(SampleTextBlock, TextBlock.FontSizeProperty);
|
|
Console.WriteLine(binding);
|
|
}
|
|
|
|
private void ExpressionButton_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
var bindingExpression = BindingOperations.GetBindingExpression(SampleTextBlock, TextBlock.FontSizeProperty);
|
|
var resolvedSource = (Slider)bindingExpression!.ResolvedSource;
|
|
var sourceFontSize = resolvedSource.FontSize;
|
|
Console.WriteLine(sourceFontSize);
|
|
}
|
|
} |