WPF(附加属性 Slider)
2013-04-11 14:15
423 查看
<Window x:Class="TestOfAttachPropertyOfSlider.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"> <Canvas > <Slider x:Name="sliderX" Canvas.Top="10" Canvas.Left="10" Width="260" Minimum="50" Maximum="200" /> <Slider x:Name="sliderY" Canvas.Top="40" Canvas.Left="10" Width="260" Minimum="50" Maximum="200" /> <Rectangle x:Name="rect" Fill="Blue" Width="30" Height="30" Canvas.Left="{Binding ElementName=sliderX,Path=Value}" Canvas.Top="{Binding ElementName=sliderY,Path=Value}" /> </Canvas> </Window>
----------------------------------------------------------------------------------->
等效的C#代码
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace TestOfAttachPropertyOfSlider { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); this.rect.SetBinding(Canvas.LeftProperty, new Binding("Value") { Source = sliderX }); this.rect.SetBinding(Canvas.RightProperty, new Binding("Value") { Source = sliderY }); } } }
相关文章推荐
- WPF(附加属性 Slider)
- WPF 附加属性的用法 (一)
- WPF 依赖属性和附加属性区别
- WPF下通过附加属性实现单实例启动
- [UWP]为附加属性和依赖属性自定义代码段(兼容UWP和WPF)
- CLR属性、依赖属性与附加属性(WPF)
- WPF 依赖属性与附加属性
- WPF 附加属性
- WPF中的依赖属性与附加属性
- WPF ListView显示GridLine(可选), 通过附加属性修改
- WPF附加属性的Set函数不调用的问题
- WPF 附加属性
- WPF菜鸟谈之依赖属性,附加属性(附加《深入浅出WPF》pdf下载)
- Wpf 附加属性(Attached Properties)
- WPF-依赖属性和附加属性
- WPF学习之依赖属性和附加属性
- WPF附加属性
- WPF快速入门1-XAML(window、Page、Application、属性、附加属性、特殊字符、保留空白、事件)
- WPF--TextBlock的ToolTip附加属性
- 【2016-11-11】【坚持学习】【Day24】【WPF 自定义控件 附加属性 自定义事件】