zoukankan      html  css  js  c++  java
  • WP7备注(32)(Relative Source|在自定义控件的属性中为子控件的属性赋值|INotifyPropertyChanged)

    Relative Source:

    <TextBlock Text="{Binding RelativeSource={RelativeSource Self},
    Path=FontFamily}" />

    在自定义控件的属性中为子控件的属性赋值:

    public partial class BorderedText : UserControl
    {
    public static readonly DependencyProperty TextProperty =
    DependencyProperty.Register("Text",
    typeof(string),
    typeof(BorderedText),
    new PropertyMetadata(null));
    
    public string Text
    {
    set { SetValue(TextProperty, value); }
    get { return (string)GetValue(TextProperty); }
    }
    }
    
    <TextBlock Text="{Binding ElementName=this, Path=Text}"/>

    用于自定义控件的子控件的属性开放,如上面那句代码,当BorderedText的Text属性赋予新值的时候,内部子控件TextBlock会自动绑定所赋的新值

    INotifyPropertyChanged:

    实现此接口的数据源类,也可以进行实时更新

    public int Second
    {
    protected set
    {
    if (value != sec)
    {
    sec = value;
    OnPropertyChanged(new PropertyChangedEventArgs("Second"));
    }
    }
    get
    {
    return sec;
    }
    }
    
    protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
    {
    if (PropertyChanged != null)
    PropertyChanged(this, args);
    }
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <StackPanel DataContext="{Binding Source={StaticResource clock}}"
    Orientation="Horizontal"
    HorizontalAlignment="Center"
    VerticalAlignment="Center">
    <TextBlock Text="{Binding Path=Hour}" />
    <TextBlock Text="{Binding Path=Minute,
    Converter={StaticResource stringFormat},
    ConverterParameter=':{0:D2}'}" />
    <TextBlock Text="{Binding Path=Second,
    Converter={StaticResource stringFormat},
    ConverterParameter=':{0:D2}'}" />
    </StackPanel>
    </Grid>
  • 相关阅读:
    技巧和诀窍;在VS 2005里优化ASP.NET 2.0Web项目的Build性能(转)
    去噪:用于验证码图片识别的类续(C#代码)
    快速申请QQ号码的技巧(图文介绍)
    vs2005中调试js
    "Take the Internet Back“挂机程序(读信息挣美元)
    javascript的编写、调试
    硬盘速度和Visual Studio性能
    Java Swing的DragAndDrop机制
    Rails 的 SNS 准备
    学习,编译ffmpeg tutorial
  • 原文地址:https://www.cnblogs.com/otomii/p/2035229.html
Copyright © 2011-2022 走看看