none
Binding string RRS feed

  • 问题

  • MainWindow.xaml:

        <Grid Initialized="MainWindow_Initialized">
            <TextBlock Height="23" HorizontalAlignment="Left" Margin="324,159,0,0" Name="ProcessingBlock" Text="TextBlock" VerticalAlignment="Top" Width="150" Background="#FFEFDFDF" DataContext="{Binding}"></TextBlock>
            <Button Content="Refresh" Height="23" HorizontalAlignment="Left" Margin="301,235,0,0" Name="Refresh" VerticalAlignment="Top" Width="75" Click="Refresh_Click" />
        </Grid>

    MainWindow.xaml.cs

        public partial class MainWindow : Window
        {
            string sProcessing = "abc";
            public MainWindow()
            {
                InitializeComponent();
                this.ProcessingBlock.SetBinding(TextBlock.TextProperty, new Binding(".") { Source = sProcessing });
            }

            private void Refresh_Click(object sender, RoutedEventArgs e)
            {
                sProcessing = "opq";
            }
        }

    我只是想简单地让TextBlock显示的数据随着String值的改变而改变。可是,点击Refresh后,sProcessing的值改变了,而TextBlock显示值没有变。为什么呢?

    2013年6月21日 4:29

答案