資料變更時,自動更新介面的內容
XAML:
<Window x:Class="WPF_DataBinding.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="133" Width="206">
<Grid Margin="0,0,2,-4">
<Button Content="{Binding ElementName=textbox,Path=Text}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="10,47,0,0"/>
<TextBox Name="textbox" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
</Grid>
</Window>
可以由上面程式碼看到,其實就是將Button的內容跟textbox的文字綁在一起,當textbox改變時,button就隨之而改變
如果想榜定的元件是Slider,就將Path改變成Value即可,因為Slider數值改變時,就是改變到Value
資料變更前
資料變更後

