• 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>
  • 相关阅读:
    学就要学好 就要学明白
    URL的基础
    各种waf识别
    Linux命令行上的上传和下载文件命令
    Linux服务器安全加固(三)
    Linux服务器安全加固(二)
    Linux服务器安全加固(一)
    Centos7配置SNMP服务
    Windows Server 系统通用安全基线配置详细
    Windows Server 2016 部署AD域控制器及添加AD域控制器
  • 原文地址:https://www.cnblogs.com/otomii/p/2035229.html
Copyright © 2020-2023  润新知